Hi Rob.

The problem was in the Notification procedure: the AComponent received 
as parameter is not ready (created). Fixed now.
Now I can create the MDI forms and a button for each of them without 
much overhead.

Thank for the answer.




Rob Kennedy wrote:
> CubicDesign wrote:
>   
>> Do you know the WindowMenu property of a (parent) form?
>> It links to a menu that lists all current MDI children of an application.
>>
>> I want to list all existing children also in other place. More exactly I 
>> want to create an interface similar with Macromedia Dreamweaver or 
>> Delphi 7, where each MDI child has its own tab from where it can be 
>> quickly accessed.
>>     
>
> Delphi 7 does not use MDI.
>
> If you want tabs, then go ahead and use tabs. Don't try to take an MDI 
> application and force it into tabs.
>
>   
>> I started the work from TForm.Notification but something went wrong. The 
>> idea was to create a new tab in a TPageControl every time a TForm was 
>> created at runtime.
>>     
>
> If you plan to do this by taking forms and re-parenting them into tabs, 
> I think you're going to have problems. Have you considered using frames? 
> You can design them visually just like forms, but they don't carry the 
> extra burden by trying to act like standalone forms.
>
>   
>> Somebody came with idea of adding a routine in each MDI form (in Create 
>> and Destroy) that will create and delete its corresponding tab, but I 
>> don't like the idea because I have many different forms derived from 
>> TFrom in my application and I have to modify them all.
>>     
>
> If they're all supposed to act a certain way, then make them all descend 
> from a common base class that acts that way. Then your modification 
> simply consists of changing all their ancestors to be that new class 
> instead of TForm.
>
>   
>> The code that I tried is:
>>
>> VAR  
>>     Initializing: Boolean= True;
>>     FormID: Integer= 0;
>>
>> procedure TfrmMain.Button1Click(Sender: TObject);
>> VAR F: TForm;
>> begin
>>  F:= TForm.Create(Self);
>>  F.Caption:= 'xx';
>>  F.Name:= 'Form'+ i2s(FormID);
>>  F.Tag:= FormID;  
>>  F.FormStyle:= fsMDIChild;
>>  F.Show;
>>  F.BringToFront;
>> end;
>>     
>
> Since you're creating the form here, in the MDI parent's code, why don't 
> you also create the button here? You have all the information you need, 
> so why rely on some underdocumented internal VCL notification to tell 
> you about it?
>
>   
>> procedure TfrmMain.FormCreate(Sender: TObject);
>> begin
>>    Initializing:= FALSE;
>> end;
>>
>>
>> procedure TfrmMain.Notification(AComponent: TComponent; Operation: 
>> TOperation);
>> VAR btn: TButton;
>> begin
>>  inherited;
>>  if NOT Initializing
>>  AND (Operation= opInsert)
>>  AND (AComponent is TForm)
>>  then
>>   begin
>>    inc(FormID);
>>      
>>    btn:= TButton.Create(Self);
>>    btn.Parent:= Self;
>>    btn.Visible:= TRUE;
>>    btn.BringToFront;
>>    btn.Top := 1;
>>    btn.Caption:=  (AComponent as TForm).Caption;    <--- AV here
>>    btn.Tag:= FormID;
>>    AComponent.Tag:= FormID;
>>   end;
>>
>> if  (Operation= opRemove) then RemoveAsocButton;
>> end;
>>
>>
>> The code creates a Tform MDI child when you push the button.
>> At this moment the Notification is aware that a new component is ready 
>> to be created. Here I want to create the list of existing MDI children - 
>> the above code tries to create a button for each of these MDI children. 
>> However it fails when at this line (AComponent as TForm).Caption.  The 
>> AComponent seems to be un-initialized.
>>     
>
> Which part causes the access violation? There are three things on that line:
>
> 1. Casting AComponent to TForm
> 2. Reading the Caption property from the result of that cast
> 3. Writing the Caption property of the button
>
>   
>> Delphi's documentation doesn't tell you big deal about Notification so I 
>> kinda got stuck.
>>     
>
>
>   
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to