Autor Beitrag
hRb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 267
Erhaltene Danke: 12



BeitragVerfasst: Sa 24.11.18 16:08 
Hallo Profis,
suche mal wieder Rat. Im Forum hat Frühlingsrolle einen abgewandelten MessageDlg vorgestellt mit dem Höhe und Breite des Fensters veränderbar ist wie folgt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Procedure ShowSizedDlg(ACaption, AMsg: string; APos: TPoint; AWidth, AHeight: Integer;
  ADlgType: TMsgDlgType; AButton: TMsgDlgButtons);
var
  temp: TForm;
begin
  temp := CreateMessageDialog(AMsg, ADlgType, AButton);
  try
    temp.Caption := ACaption;
    temp.Left := APos.X;
    temp.Top := APos.Y;
    temp.Width := AWidth;
    temp.Height := AHeight;
    temp.ShowModal;
  finally
    temp.Free;
  end;
end;

Solange es nur um Bestätigung mit Ok geht, funktioniert auch alles bestens. Ich wollte nun die Routine zur Mehrfachabfrage abändern als Funktion, die den Rückgabewert auswertet wie folgt:
ausblenden Delphi-Quelltext
1:
2:
Function ShowSizedDlg(ACaption, AMsg: string; APos: TPoint; AWidth, AHeight: Integer;
  ADlgType: TMsgDlgType; AButton: TMsgDlgButtons)[b]:integer;[/b]

Mein Code lautet:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
...
if ShowSizedDlg('Rückfrage', Text1, Point(left, top), Breite, Hoehe,
   mtConfirmation, [mbYes, mbCancel]) <> mrYes 
   then exit
   else
...

Nun stelle ich fest, dass ShowSizeDlg überhaupt keinen brauchbaren Rückgabewert liefert (vieles schon versucht). Die Routine führt immer zu "exit".
Frage:
was mache ich falsch?,
müsste im finally-Zweig ein Befehl stehen: "Result:= ???(Rückgabewert)". (temp ist ein TForm-Object),
Definiere ich den Rückgabewert der Function nicht mit integer sondern mit TMsgDlgBtn, dann lässt sich das Programm nicht übersetzen.
Habe Knoten im Kopf. Wer kann helfen?
hRb
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 24.11.18 17:39 
Das sollte eigentlich gehen wenn du die Zeile mit dem ShowModal in der Funktion mit
ausblenden Delphi-Quelltext
1:
result := temp.ShowModal;					

ersetzt.

_________________
We are, we were and will not be.
hRb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 267
Erhaltene Danke: 12



BeitragVerfasst: Mo 26.11.18 21:38 
Hallo Gausi,
Dein Vorschlag lässt sich zwar compilieren, der Befehl liefert jedoch zur Laufzeit eine Zugriffsverletzung mit Programmabruch - leider.
hRb
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 26.11.18 22:22 
Das funktioniert bei mir einwandfrei ... :gruebel:
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 ShowSizedDlg(ACaption, AMsg: string; APos: TPoint; AWidth, AHeight: Integer;
  ADlgType: TMsgDlgType; AButton: TMsgDlgButtons): Integer;
var
  temp: TForm;
begin
  temp := CreateMessageDialog(AMsg, ADlgType, AButton);
  try
    temp.Caption := ACaption;
    temp.Left := APos.X;
    temp.Top := APos.Y;
    temp.Width := AWidth;
    temp.Height := AHeight;
    result := temp.ShowModal;
  finally
    temp.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var tmp: Integer;
begin
    tmp := ShowSizedDlg('Hallo''Klicke auf einen Knopf', Point(10,10), 500500, mtConfirmation, [mbYes, mbCancel]);
    Button1.Caption := IntToStr(tmp);
end;


An welcher Stelle kommt denn bei dir die Zugriffsverletzung?

_________________
We are, we were and will not be.
hRb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 267
Erhaltene Danke: 12



BeitragVerfasst: Mo 10.12.18 18:00 
Hallo Gausi,
tut mir Leid für den Wirbel. Hatte den Result-Befehl nicht richtig angepasst. Soll nicht wieder vorkommen.
Danke und Gruß
hRb