Autor Beitrag
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Sa 22.01.11 10:21 
Hi, Sebastian,
danke für deine Nachsorge, hier der xMessageDlg-Code.
Bin mal neugierig, was du findest:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
function TBuchMain.xMessageDlg(const Msg: string; DlgType : TMsgDlgType;
            Buttons : TMsgDlgButtons; Captions: array of string; myFont:TFont) : Integer;
var aMsgDlg         : TForm;
    CaptionIndex, i : integer;
    dlgButton       : TButton;  // uses stdctrls
begin
  aMsgDlg := CreateMessageDialog(Msg, DlgType, buttons);
  aMsgDlg.Font.style := [];   //myFont, zB. [fsitalic] ;
  aMsgDlg.setbounds(300,520,650,200);
  CaptionIndex := 0;
  for i := 0 to aMsgDlg.ComponentCount - 1 do  // alle Objekte des Dialoges testen
  begin
    if (aMsgDlg.Components[i] is TButton) then  // wenn es ein Button ist, dann...
    begin
      dlgButton := TButton(aMsgDlg.Components[i]);
      dlgButton.Left := 100*(i-2) + 10*(i+1);
      dlgbutton.width := 100;   // default=68;
      if CaptionIndex > High(Captions) then Break;
      dlgButton.Caption := Captions[CaptionIndex]; // Beschriftung = Captions-array
      Inc(CaptionIndex);
    end;
  end;
  Result := aMsgDlg.ShowModal;
end;


Bis denne, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 22.01.11 11:25 
aMsgDlg wird nicht freigegeben.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
aMsgDlg := ...
try
  ...
  Result := aMsgDlg...
finally
  aMsgDlg.Free;
end;

Für diesen Beitrag haben gedankt: D. Annies
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Sa 22.01.11 14:30 
Danke, Sebastian! - das heißt also: jedesmal, wenn ich etwas der Form .create habe,
sollte ich mit try .. except arbeiten und mit free, richtig?
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 22.01.11 16:17 
Mit try..finally. ;-) Es sei denn du hast einen Owner angegeben. In diesem Fall gibt dieser Owner bei dessen Zerstörung das Objekt frei. Wenn du das selbst machen möchtest, solltest du nil angeben.

In diesem Fall hier wird innerhalb CreateMessageDialog Application als Owner verwendet. Das heißt beim Beenden der Anwendung würde der Dialog auch freigegeben. Aber eben erst dann, und wenn du zu viele solcher Dialoge erzeugst, bleiben die alle bis dahin im Speicher. ;-)

Für diesen Beitrag haben gedankt: D. Annies
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 23.01.11 21:57 
Danke, Sebastian

_________________
ut vires desint, tamen est laudanda voluntas