* * *

Author Topic: [SOLV]Help with coding: making things invisible, to show just at the right time.  (Read 741 times)

mundim

  • New member
  • *
  • Posts: 11
So, I'm making a program and there's a button that when clicked will do some math and show the result in a Editbox. What I want is that when the result is 6 or more, I want a image and a piece of text (label) to appear at some place and when it's below 6, I want another image and a different text to appear on the same place. Any ideas of how do I do that?
« Last Edit: February 24, 2012, 11:21:20 pm by mundim »

Leledumbo

  • Hero Member
  • *****
  • Posts: 2989
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #1 on: February 23, 2012, 03:04:20 am »
  • Create those controls (image and label) dynamically, or
  • Put them on the form, set their Visible property to false. After doing the math, set Visible to true
Different image (Picture property) and different text (Caption property) could be done from code by both above approaches.

joseme

  • Jr. Member
  • **
  • Posts: 95
    • Logosoft sistemas
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #2 on: February 23, 2012, 03:21:59 am »
You should evaluate the Editbox text, on the OnChange property. Depending on text value, you can assign the image and the label accordingly.
un aporte a la comunidad:
http://pascalylazarus.blogspot.com/

mundim

  • New member
  • *
  • Posts: 11
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #3 on: February 23, 2012, 02:33:33 pm »
Thanks for the help, it should work!  :D

I just have this doubt on how to make the "6 or more" code for the Editbox, like If ""Edit1.text := 6 or more than Image.Visible := True, else Image2.Visible := True.""

I'm not sure how to make this "6 or more"...

HappyLarry

  • Jr. Member
  • **
  • Posts: 86
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #4 on: February 23, 2012, 03:02:38 pm »
You first need to use StrToint to convert a string to an integer.

If StrToInt(edit1.text) >= 6 then
begin
   Shape1.visible:=true;
   Label1.caption:='hello';
   Shape2.visible:=false;
   Label2.caption:='';
end
else
begin
   Shape1.visible:=false;
   Label1.caption:='';
   Shape2.visible:=true;
   Label2.caption:='goodbye';
end;
« Last Edit: February 23, 2012, 04:28:11 pm by HappyLarry »
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

Arbee

  • Full Member
  • ***
  • Posts: 219
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #5 on: February 23, 2012, 03:44:18 pm »
or ...
Code: [Select]
  gt6 := (StrToInt(edit6.text) >= 6);  // gt6 is a boolean variable
  Shape1.visible := gt6;
  Label1.caption.visible := gt6;
  Shape2.visible := (not gt6);
  Label2.caption.visible := (not gt6);
0.9.30/2.4.2 (29749)  XP SP3 & OS X 10.6.8

User137

  • Hero Member
  • *****
  • Posts: 503
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #6 on: February 23, 2012, 04:42:49 pm »
Ahaha, or one more style:
Code: [Select]
  Shape1.visible := (StrToInt(edit6.text) >= 6);
  Label1.visible := Shape1.visible;
  Shape2.visible := not Shape1.visible;
  Label2.visible := not Shape1.visible;

mundim

  • New member
  • *
  • Posts: 11
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #7 on: February 23, 2012, 04:56:17 pm »
Haha, thanks for all the asnwers! I`m almost there... Put it seems that there is still a problem with the coding. When the Editbox is less than 6 AND 6 or more, it shows the image and the text that are only supposed to appear only when it`s less than 6. See if you can spot any mistake in the coding, please:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
 Media := StrToFloat(Bim1.Text)+StrToFloat(Bim2.Text)+StrToFloat(Bim3.Text)+StrToFloat(Bim4.Text)*3;
 Answermedia := (Media)/6          ;
 Mfinal.Text := FloatToStr(Answermedia);
 If StrToInt(Mfinal.text) >= 6 then
   Image1.Visible:= True;
   L1.Visible:= True;
   L2.Visible := True ;
   Image2.Visible:= False;
   L3.Visible := False;
   L4.Visible:= False;
  If StrToInt(Mfinal.text) <= 6 then
   Image1.Visible:= False;
   L1.Visible:= False;
   L2.Visible := False ;
   Image2.Visible:= True;
   L3.Visible := True;
   L4.Visible:= True;
end;

User137

  • Hero Member
  • *****
  • Posts: 503
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #8 on: February 23, 2012, 05:29:12 pm »
To put short, you forgot "begin" and "end".
Pascal as language doesn't follow line changes. So this:
Code: [Select]
if a<b then begin
  DoSomething1;
  DoSomething1;
end else begin
  DoSomething3;
end;
Would also work even like:
Code: [Select]
if a<b then begin DoSomething1;DoSomething1;end else begin DoSomething3;end;See, indent alone doesn't make code belong to IF-clause.

Also, "less than 6" is marked "n<6".
"n<=6" would mean "less than or equal to 6".
« Last Edit: February 23, 2012, 05:32:20 pm by User137 »

Shebuka

  • Sr. Member
  • ****
  • Posts: 325
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #9 on: February 23, 2012, 05:49:19 pm »
mundim: it will be a good idea to read 'Pascal for Dummies' or 'Delphi for Dummies' or similar manual.

mundim

  • New member
  • *
  • Posts: 11
Re: Help with coding: making things invisible, to show just at the right time.
« Reply #10 on: February 23, 2012, 09:21:16 pm »
Thanks, it worked perfectly!  :D

And Shebuka, thanks for the advice, do you know if I can find this books online and others helpful guides? I'm fairly new to programming at all, I have been watching some videos and reading some guides, but sometimes I just can't find what I'm looking for, so I ask here...

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads