Link to home
Start Free TrialLog in
Avatar of pr2501
pr2501

asked on

Difference between Form create , Form activate, Form show and Form paint

What is the difference
Between Form create
Form activate
Form show
And form paint

If I use form paint in get in  edit1:
C:\f\f.rtf

If I use FormActivate or FormShow or FormCreate  in get in  edit1:
C:\\.rtf

And once the form is “on”
From the button click event if I use FormCreate  I also get
C:\f\f.rtf


Form2 is avto-created, Form1 is set as available form

If I set form 1 as avto created I get error in line:
 
  S := TFileStream.Create(sFile, fmOpenReadwrite or fmShareDenyNone)

In attached code.

So what must i do with form1 to resolve this kind of problems

procedure TForm1.FormActivate(Sender: TObject);
var
  sfile:string;
  S: TFileStream;
  oldstate: Boolean;

begin
richedit2.ReadOnly:=false;
 sFile:= form2.ExtractPath(Form2.caption)+'\'+form1.Caption+'\'+form1.Caption+'.rtf';
Edit2.Text:=  sFile;
  if FileExists(sFile) then
    S := TFileStream.Create(sFile, fmOpenReadwrite or fmShareDenyNone)
  else
    S := TFileStream.Create(sFile, fmCreate or fmShareDenyNone);
   try
     richedit2.PlainText := False;
     richedit2.MaxLength := s.Size; // ensures long docs can display
     richedit2.Lines.loadfromStream (S);
    finally
    S.Free;
    end;
  begin
  oldstate := RichEdit2.HideSelection;
  RichEdit2.HideSelection := False;
  RichEdit2.CaretPos := Point(0, RichEdit2.Lines.Count-1);
  RichEdit2.HideSelection := oldstate;
  end;
  richedit2.ReadOnly:=true ;
end;

Open in new window

SOLUTION
Avatar of RezaSadigh
RezaSadigh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pr2501
pr2501

ASKER

Thank you Sinisa.  It works now. Normaly i would close the qustion and give points to you.  But.
Can you also explain me this trick, because from the teory above i can not anderstand.
Event OnActivate fires every time when you ativate form after you go away. This is first time when application is started and every time when you go to another form and go back.
Trick is to set variable that onactivated is already started first time.