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

Tomas Stejskal tose at netsource.cz
Tue Jan 31 09:05:35 CET 2006


I think better OO solution is to create wrapper method around the 
external function.

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

TEnvironment = class(TObject)
public
  function GetEnvironment(const AName: String): String;
end;

function TEnvironment.GetEnvironment(const AName: String): String;
begin
  Result := String(getenv(PChar(AName)));
end;

Tomas Stejskal

Amir Aavani wrote:

> 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 at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel





More information about the fpc-devel mailing list