Recent

Author Topic: [SOVLED] How to check for true with Events?  (Read 3549 times)

userx-bw

  • Full Member
  • ***
  • Posts: 178
[SOVLED] How to check for true with Events?
« on: May 08, 2015, 04:24:41 pm »
This is the pseudo code Logic,

If form1 is hidden then form2 is showing. therefore load an image into forms2's image instead.

else

form1 is showing and Form2 is hidden therefore load an image into form1's image instead


this is the code that is not written right but the logic is still there
Code: [Select]

        if (Form1.OnHide)
        then
          Form2.Image1.Picture.LoadFromFile(Form1.ImageList[Form1.ImageIndex])
                                 
        else
          //Form1
            Image.Picture.LoadFromFile(ImageList[ImageIndex]);
        end;
               

what is the correct way to check for Even states using pascal code?
« Last Edit: May 08, 2015, 05:08:51 pm by userx-bw »
My Finished Projects
https://sourceforge.net/projects/mhsetroot/
https://sourceforge.net/projects/gmhsetrootfreepascalfrontend/

HP Elitetbook 6930p Dual Core Intel vPro 2.66 gHz
VOID (Linux) 64bit

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12984
  • FPC developer.
Re: How to check for true with Events?
« Reply #1 on: May 08, 2015, 04:31:43 pm »
No, onhide is custom code to be run when a form is hidden. It says nothing about being hidden or the ability to.

userx-bw

  • Full Member
  • ***
  • Posts: 178
Re: How to check for true with Events?
« Reply #2 on: May 08, 2015, 04:36:33 pm »
No, onhide is custom code to be run when a form is hidden. It says nothing about being hidden or the ability to.

so therefore you are not understanding the logic in what I am trying to do then  :'( , only that if a form is hidden then only custom code can be ran ?

therefore lets do it like this then

Code: [Select]


        if (Form1.isVisible)
        then
  //Form1
          Image.Picture.LoadFromFile(ImageList[ImageIndex]); 
                                 
        else
       
          Form2.Image1.Picture.LoadFromFile(Form1.ImageList[Form1.ImageIndex])
        end;

the point being is how do Check to be sure that a Form is showing so the program knows which from to transfer the image to?

EDIT:
it is an EVENT therefore it has to have a way of checking for it
« Last Edit: May 08, 2015, 05:08:31 pm by userx-bw »
My Finished Projects
https://sourceforge.net/projects/mhsetroot/
https://sourceforge.net/projects/gmhsetrootfreepascalfrontend/

HP Elitetbook 6930p Dual Core Intel vPro 2.66 gHz
VOID (Linux) 64bit

userx-bw

  • Full Member
  • ***
  • Posts: 178
Re: How to check for true with Events?
« Reply #3 on: May 08, 2015, 05:06:19 pm »
the onHide Even sets the forms Visible properties to false  as it is a boolean therefore one can just use this property to check programmatically if the form is in a hidden state or not.

Code: [Select]


if not (Form1.Visible)
        then
             Form2.Image1.Picture.LoadFromFile(Form1.ImageList[Form1.ImageIndex])
        else
             begin
            Image.Picture.LoadFromFile(ImageList[ImageIndex]);
        end;       


Form.OnShow

When the form is shown (e.g. when loading the form or setting its .Visible property to true), this event is fired - just before the form is visible. This allows you to modify the visual appearance of controls (e.g. disable certain controls) without flickering.
My Finished Projects
https://sourceforge.net/projects/mhsetroot/
https://sourceforge.net/projects/gmhsetrootfreepascalfrontend/

HP Elitetbook 6930p Dual Core Intel vPro 2.66 gHz
VOID (Linux) 64bit

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to check for true with Events?
« Reply #4 on: May 08, 2015, 05:15:51 pm »
it is an EVENT therefore it has to have a way of checking for it

You have three "it"s in that comment, and none of them has a clear referent.

Perhaps you are looking for this sort of code?

Code: [Select]
procedure LoadImageToVisibleForm;
var
  r: TRect;
begin
  if Form1.Visible then begin
    r:=Rect(0, 0, Form1.Image1.Width, Form1.Image1.Height);
    Form1.ImageList.StretchDraw(Form1.Image1.Canvas, Form1.ImageIndex, r)
  end
  else if Form2.Visible then
    r:=Rect(0, 0, Form2.Image1.Width, Form2.Image1.Height);
    Form1.ImageList.StretchDraw(Form2.Image1.Canvas, Form1.ImageIndex, r) ;
end;

userx-bw

  • Full Member
  • ***
  • Posts: 178
Re: How to check for true with Events?
« Reply #5 on: May 08, 2015, 05:43:43 pm »
it is an EVENT therefore it has to have a way of checking for it

You have three "it"s in that comment, and none of them has a clear referent.

it := Form because that is the main topic of the question at hand. I can see you are having trouble with statements with the word "it" in them. so let me rephrase that for you.

a Form has an Event of onHide attached to itself therefore there has to be a way of checking to see if that same Form is in fact in a show state or not. this would lead one to assume that it is a Boolean. Showing = true NotShowing=true.

Which ever state the Form is in then a true can be assigned to that state the form is in. therefore only to leave a false for the other state that this Form could be in. The form is either showing or not showing. The True or False would then be assigned to each state respectively in the option of the one that programmed the Form to have a return value of Boolean for each state the Form has been placed in.

The form being in a hidden state should have a true set to it somewhere. or at least a Boolean of true or false.

hows that no "IT's" in that statement.  it is more words but says the same thing.



Code: [Select]
procedure LoadImageToVisibleForm;
var
  r: TRect;
begin
  if Form1.Visible then begin
    r:=Rect(0, 0, Form1.Image1.Width, Form1.Image1.Height);
    Form1.ImageList.StretchDraw(Form1.Image1.Canvas, Form1.ImageIndex, r)
  end
  else if Form2.Visible then
    r:=Rect(0, 0, Form2.Image1.Width, Form2.Image1.Height);
    Form1.ImageList.StretchDraw(Form2.Image1.Canvas, Form1.ImageIndex, r) ;
end;

your coding is correct in logic but it looks to not be Pascal, C perhaps.

else if Form2.Visible then

that whole block statement of code of yours is in itself is a Boolean - yes or no - or - true or false

Code: [Select]
if Visible is true then do something

else

do something different // that is the false part of the Boolean

if you had read the last post just before yours you'd of seen that I already figured it out, and how.

Thank you anyways.
« Last Edit: May 08, 2015, 06:05:23 pm by userx-bw »
My Finished Projects
https://sourceforge.net/projects/mhsetroot/
https://sourceforge.net/projects/gmhsetrootfreepascalfrontend/

HP Elitetbook 6930p Dual Core Intel vPro 2.66 gHz
VOID (Linux) 64bit

 

TinyPortal © 2005-2018