nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

Re: Problema con inputbox

X-FaceVon: Mauro Falzari (spamtrap@sertel.net) [Profil]
Datum: 22.01.2007 23:57
Message-ID: <Xns98C194B10310001001010101010001@127.0.0.1>
Newsgroup: it.comp.lang.delphi
Il giorno 22 gennaio 2007, Brunello ha scritto:

> visto che faceva perfettamente al mio caso ho provato a utilizzare la
> quarta opzione ma mi ha dato un errore di sintassi infatti sono andato
> a guardare la unit Dialogs ed è implementata solo la prima. Sapete
> dirmi perchè grazie Brunello.

non saprei dirti il perchè non è stata implementata, però non ci
vuole
molto a crearti una cosa del genere ("incapsulare" una form in una
funzione). Ti ho buttato giù qui due righe di codice per farti vedere come
ottenere una semplice funzione di questo genere.

Si tratta di una form con una Label e un Edit, che poi viene mostrata
chiamando una procedura. Viene restituito anche un valore digitato
dall'utente.

Il sorgente di Project1.dpr è
//***************************************
program Project1;

uses
Forms, Dialogs,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

var
i: Integer;
begin
i := 0;
ExecuteMyDialogBox('Immetti qui il valore', i);
ShowMessageFmt('Il valore è: %d', [i]);
end.


Quello della form è
//*******************************************
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls;

type
TMyDialogBox = class(TForm)
Label1: TLabel;
Edit1: TEdit;
private
function GetTitle: string;
procedure SetTitle(const Value: string);
function GetDialogText: string;
procedure SetDialogText(const Value: string);
function GetValue: Integer;
procedure SetValue(const Value: Integer);
{ Private declarations }
public
property Title: string read GetTitle write SetTitle;
property DialogText: string read GetDialogText write SetDialogText;
property Value: Integer read GetValue write SetValue;
end;

procedure ExecuteMyDialogBox(const DialogText: string; var A: Integer;
const Title: string = '');

implementation

{$R *.dfm}

procedure ExecuteMyDialogBox(const DialogText: string; var A: Integer;
const Title: string = '');
var
MyDialogBox: TMyDialogBox;
begin
MyDialogBox := TMyDialogBox.Create(nil);
try
if Title = '' then MyDialogBox.Title := '(senza titolo)' else
MyDialogBox.Title := Title;
MyDialogBox.DialogText := DialogText;
MyDialogBox.Value := A;
MyDialogBox.ShowModal;
A := MyDialogBox.Value;
finally
MyDialogBox.Free
end;
end;

function TMyDialogBox.GetDialogText: string;
begin
Result := Label1.Caption
end;

function TMyDialogBox.GetTitle: string;
begin
Result := Caption
end;

function TMyDialogBox.GetValue: Integer;
begin
Result := StrToIntDef(Edit1.Text, 0);
end;

procedure TMyDialogBox.SetDialogText(const Value: string);
begin
Label1.Caption := Value
end;

procedure TMyDialogBox.SetTitle(const Value: string);
begin
Caption := Value
end;

procedure TMyDialogBox.SetValue(const Value: Integer);
begin
Edit1.Text := IntToStr(Value)
end;

end.


--
Mauro Falzari

"E' l'orribile filo di una stoffa
intessuta di cavi e gomene.
Attraversato da un vento polare,
sorvolato da uccelli rapaci".
(Herman Melville, in "Moby Dick", Londra 1851)

[ Auf dieses Posting antworten ]

Antworten