I do NOT close the mainform. I want to refactor the Wks form. I call
that from within the MainForm. I tried using release, as follows:
    class procedure TGenericworkstation.Refactor(NewClass: class of
    TGenericWorkstation);
    begin
        if (Wks = nil) or not (Wks is NewClass) then
        begin
        if Wks <> nil then 
                Wks.Release;
            Wks:= NewClass.Create(nil);
            Application.ProcessMessages;         // This is where I
crash!!!
        end;
    end;

And I crash.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 21, 2006 1:10 PM
To: [email protected]
Subject: Re: [delphi-en] Trouble refactoring a form


Hi Assaf,
The Mainform of a delphi application is something special! When it is
closed, the application stops! I would suggest, you open a second form
(type workstation one or two) after hiding your Mainform. Another point
is: You should NOT Free a form! Use Release instead. At the time of
destroying the form there might be still something in the associated
message-queue. "Release" takes care of that.

Have fun
Bib

>     Hello all. I'm using Delphi-7, and I'm trying to do the following:
>     I have a MainForm, which checks a certain parameter (let's call it
>     workstation-type). If it is one kind, I want to create the form as
a
>     type1-workstation. Otherwise, it should be a type2-workstation.
>     both types (1,2) inherit from a generic-workstation class
(inherited
>     from the repository)
>      
>      
>     The problem starts, when I want to change the form type in
run-time, and
>     continue running. When I try to free the (global) form variable,
and
>     create a new instance, I crash on an access violation. If I don't
free
>     the pointer I don't crash, but the memory usage increases (and the
leak
>     is waiting to burst).
>      
>     Any ideas how to solve the access violation, or better yet, change
the
>     form without having to kill it first?
>      
>      
>     What I do is as follows:
>      
>     procedure TMainForm.LoadWksForm;
>     begin
>         repeat 
>             if parameter = 1 then
>                 TGenericWorkstation.Refactor(TType1Workstation)
>             else
>                 TGenericWorkstation.Refactor(TType1Workstation);
>         until Wks.ModalResult = mrOk;
>     ...
>     class procedure TGenericworkstation.Refactor(NewClass: class of
>     TGenericWorkstation);
>     begin
>         if (Wks = nil) or not (Wks is NewClass) then
>         begin 
>             FreeAndNil(Wks);
>             Wks:= NewClass.Create(nil);
>             Application.ProcessMessages;         // This is where I
crash!!!
>         end;
>     end;
>     ...
>     procedure TGenericworkstation.ChangeType;
>     begin
>         ModalResult:= mrOk;
>     end;
>      
>     Assaf Stone
>     Spacelogic ltd.
>     [EMAIL PROTECTED]
>     Tel: 972-9-8855565 ext. #315
>      
>     
>     
>     [Non-text portions of this message have been removed]
>     
>     
>     
>     -----------------------------------------------------
>     Home page: http://groups.yahoo.com/group/delphi-en/
>     To unsubscribe: [EMAIL PROTECTED] 
>     Yahoo! Groups Links
>     
>     
>     
>      
>     
>     



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links



 


 This mail arrived via mail.pineapp.net
 
************************************************************************
************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals &
computer viruses.
************************************************************************
************


-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to