[fpc-devel] How to call (access) to an external procedure!

2006-01-30 Thread Amir Aavani

dear friends,
I know that if want to use an external variable/procedure in fpc, i 
should use the following code:


function GetEnvironment (const Name: PChar): PChar; cdecl; external 'c' 
name 'getenv';


but how could i add for example  GetEnvironment function to a class 
(TEnvironment)!

Is there any good (OO) way?

Is it a good idea to use a following method:

TGetEnvironmentFunction= function : PChar;
TEnvironment= class (TObject)
private
 ...
public
 GetEnvironment: TGetEnvironment;
 procedure SetGetEnvironmentFunction (AFunction: TGetEnvironmentFunction);
 ...
end;

procedure TEnvironment.SetGetEnvironmentFunction (AFunction: 
TGetEnvironmentFunction);

begin
 GetEnvironment:= AFunction;
end;



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] How to call (access) to an external procedure!

2006-01-30 Thread Geno Roupsky
This particular function could be declared as this:

TEnvironment = class
public
  class function GetEnvironment(const Name: PChar): PChar; cdecl;
end;

class function GetEnvironment(const Name: PChar): PChar; cdecl; external
'c' name 'getenv';

Of course this is not very useful but the idea for methods is this. Just
keep in mind that methods have a hidden parameter Self pointing to the
object. When method is declared as cdecl it is the first parameter.

Tia,

Geno Roupsky

В вт, 2006-01-31 в 10:05 +0330, Amir Aavani написа:
 dear friends,
 I know that if want to use an external variable/procedure in fpc, i 
 should use the following code:
 
 function GetEnvironment (const Name: PChar): PChar; cdecl; external 'c' 
 name 'getenv';
 
 but how could i add for example  GetEnvironment function to a class 
 (TEnvironment)!
 Is there any good (OO) way?
 
 Is it a good idea to use a following method:
 
 TGetEnvironmentFunction= function : PChar;
 TEnvironment= class (TObject)
 private
   ...
 public
   GetEnvironment: TGetEnvironment;
   procedure SetGetEnvironmentFunction (AFunction: TGetEnvironmentFunction);
   ...
 end;
 
 procedure TEnvironment.SetGetEnvironmentFunction (AFunction: 
 TGetEnvironmentFunction);
 begin
   GetEnvironment:= AFunction;
 end;
 
 
 
 ___
 fpc-devel maillist  -  fpc-devel@lists.freepascal.org
 http://lists.freepascal.org/mailman/listinfo/fpc-devel
 

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] How to call (access) to an external procedure!

2006-01-30 Thread Marco van de Voort
 dear friends,
 I know that if want to use an external variable/procedure in fpc, i 
 should use the following code:
 
 function GetEnvironment (const Name: PChar): PChar; cdecl; external 'c' 
 name 'getenv';

Note that this procedure is already available as fpgetenv from unit
baseunix, and in a more friendly style as getenvironmentvariable using
plain strings from sysutils.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel