comment avoir accès aux variables et fonctions d'une forme depuis une autre fonction?
Bonjour, j'ai le code suivant et ma question est mise en commentaire dans le code::
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
unit FM_Main;
interface
uses {...}
type
TF_Main = class(TForm)
private {...}
protected {...}
public
function g (...):string;
procedure h(....);
a: TADOConnection;
b: TADOQuery;
end;
function f (r : string) : string;
implementation
function TF_Main.g(...):string;
begin
{corps de la fonction g}
end;
procedure TF_Main.h(...);
begin
{corps de la fonction g}
end;
function f (r : string) : string;
begin
//Mon souci c'est comment avoir accès au variable a et b ainsi qu'à g et h
end; |
Merci D'avance les gas
ca marche + petit probleme
Citation:
Envoyé par ShaiLeTroll
Soit la variable globale généralement associé à une form, soit tu passe un paramètre en plus qui est une form de la classe TF_Main
soit par soucis de logique objet, tu fais une méthode de classe qui prend en paramètre la form
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
unit FM_Main;
interface
uses {...}
type
TF_Main = class(TForm)
private {...}
protected {...}
public
function g (...):string;
procedure h(....);
class function f (r : string) : string;
a: TADOConnection;
b: TADOQuery;
end;
implementation
function TF_Main.g(...):string;
begin
{corps de la fonction g}
end;
procedure TF_Main.h(...);
begin
{corps de la fonction g}
end;
class function TF_Main.f (r : string; const F_Main: TF_Main) : string;
begin
//Mon souci c'est comment avoir accès au variable a et b ainsi qu'à g et h
end; |
C'est la solution qui me va le meiux, ca compile. merci.
A moins j'ai une petite question: voici la fonction d'où j'appelle les autres variables de TF_Main:
Code:
1 2 3 4 5 6 7 8 9 10
|
function GetTypeDeal(refcon : string; const F_Main: TF_Main): string;
begin
F_Main.AdoQuery1.Connection := F_Main.ADOConnectionSophis;
F_Main.ADOQuery1.SQL.Text := 'select sicovam from histomvts where refcon ='+ refcon ;
F_Main.ADOQuery1.open;
F_Main.ADOQuery1.SQL.Text:='select ADI_GETALLOTEMENT(' + F_Main.ADOQuery1.FieldByName('SICOVAM').AsString + ') as colonne from dual';
F_Main.ADOQuery1.open;
Result := F_Main.ADOQuery1.FieldByName('colonne').AsString;
end; |
mais le problème c'est que à l'execution mon programe plante à la premiere ligne de cette fonction avec un message d'erreur de type EAccess Violation...
Je ne sais pas d'ou ca vient! Je précise que ADOConnectionSophis est un champs du type TF_Main qui est une connexion à une certaine base de données. je crois qu'àprès l'appel de la fonction ces champs sont ignorés !!!! enfin j'en sais pas trop.
Voyez vous le pb. Merci d'avance