Need help Delphi/Pascal to Pure

Just starting out? Need help? Post your questions and find answers here.
Joshua314
New User
New User
Posts: 7
Joined: Sat Aug 20, 2005 12:32 pm

Need help Delphi/Pascal to Pure

Post by Joshua314 »

Hi Volks,

i need a little help to convert a Deplhi/Pascal to Pure

The Problem is that.
The translate of this Procedure

TSucheTelefonnummer = procedure( Nummer : PChar; var EintragListe : PDLLEintrag; var EintragAnzahl : LongInt ); stdcall;

In the red part my problem
At the Var Parameter the search number of Phone book ... At eintragAnzahl the result of Count result .. This is ok and works.
But the Result of structure doesnt work. Please help.

Code: Select all

;*************************************** Original *************************************
;{
; Unit Unit1;
; 
; Interface
; 
; uses
; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DdeMan;
; 
; type
;   TitelArray            = Array[1..5] of Byte;
; 
;   PDLLEintrag           = ^TDLLEintrag;
;   TDLLEintrag           = Packed Record
;     Markiert          : Boolean;
; 
;     Titel             : TitelArray;
; 
;     Adel              : Byte;
;     NameVorsatz       : Byte;
;     NameZusatz        : Byte;
; 
;     Geschlecht        : Byte;
;     Vorname           : String[30];
;     Anrede            : String[10];
;     Name              : String[120];
;     Zusatz            : String[120];
;     Ortsteil          : String[40];
;     Strasse           : String[46];
;     Hausnummer        : String[10];
;     HausnummerZusatz  : String[20];
;     Land              : String[3];
;     PLZ               : String[5];
;     Ort               : String[70];
;     Vorwahl           : String[10];
;     TelZusatz         : String[15];
;     Telefon           : String[20];
;   End;
;  
;   PDLLArray             = ^TDLLArray;
;   TDLLArray             = Array[1..1] of TDLLEintrag;
; 
; 
;   TUseVersion = Procedure(V : Byte); stdcall;
;   TSucheTelefonnummer = Procedure( Nummer : PChar; var EintragListe : PDLLEintrag;
;                                    var EintragAnzahl : LongInt ); stdcall;
; 
; 
;   TForm1 = class(TForm)
;     Button1: TButton;
;     Edit1: TEdit;
;     ListBox1: TListBox;
;     RadioButton1: TRadioButton;
;     RadioButton2: TRadioButton;
;     Procedure Button1Click(Sender: TObject);
;     Procedure RadioButton2Click(Sender: TObject);
;     Procedure RadioButton1Click(Sender: TObject);
;   private
;     { Private-Deklarationen }
;     DllHdl : THandle;
;   public
;     { Public-Deklarationen }
;   End;
; 
; 
; var
;  Form1 : TForm1;
; 
;  DllHdl : THandle;
;  FuncPtr : TFarProc;
;  PSucheTelefonnummer : TSucheTelefonnummer;
;  PUseVersion : TUseVersion;
; 
; implementation
; 
; {$R *.DFM}
; 
; Procedure TForm1.Button1Click(Sender: TObject);
; var
;  EList : PDLLEintrag;
;  ETemp : PDLLArray;
;  ECount : LongInt;
;  co : LongInt;
; begin
;   PSucheTelefonnummer( PChar( Edit1.Text ), EList, ECount );
;   ETemp := PDLLArray( EList );
; 
;   For co := 1 To ECount do begin
;    ListBox1.Items.Add( ETemp^[co].Name + #32 + ETemp^[co].Vorname + #32 +
;                        ETemp^[co].Vorwahl + '-' + ETemp^[co].Telefon );
;   End;
; End;
; 
; Procedure TForm1.RadioButton2Click(Sender: TObject);
; begin
;   PUseVersion( 2 );
; End;
; 
; Procedure TForm1.RadioButton1Click(Sender: TObject);
; begin
;   PUseVersion( 1 );
; End;
; 
; initialization
;   DllHdl := 0;
;   FuncPtr := Nil;
; 
;   DllHdl := LoadLibrary( 'rufid.dll' );
;   If DllHdl = 0 then
;    Halt;
; 
;   FuncPtr := GetProcAddress( DllHdl, 'SucheTelefonnummer' );
;   If FuncPtr = nil then
;     Halt
;   Else
;    @PSucheTelefonnummer := FuncPtr;
; 
;   FuncPtr := GetProcAddress( DllHdl, 'UseVersion' );
;   If FuncPtr = nil then
;     Halt
;   Else
;    @PUseVersion := FuncPtr;
; 
; End.
;}
;****************************************Eigener Versuch ******************************
;************************************* Vars
EnableExplicit
Global *SucheTelefonnummer,*UseVersion





; DLLPath:= DllPath + 'rufid.dll';
;
; DllHdl := LoadLibrary(PChar (DLLPath));
;
; If DllHdl > 0 then
;   begin
;     FuncPtr := GetProcAddress( DllHdl, 'SucheTelefonnummer' );
;     If FuncPtr <> nil then @PSucheTelefonnummer := FuncPtr;
;
;     FuncPtr := GetProcAddress( DllHdl, 'UseVersion' );
;     If FuncPtr <> nil then @PUseVersion := FuncPtr;
;
;   End;

; TDLLEintrag           = Packed Record
;     Markiert          : Boolean;
;
;     Titel             : TitelArray;
;
;     Adel              : Byte;
;     NameVorsatz       : Byte;
;     NameZusatz        : Byte;
;
;     Geschlecht        : Byte;
;     Vorname           : String[30];
;     Anrede            : String[10];
;     Name              : String[120];
;     Zusatz            : String[120];
;     Ortsteil          : String[40];
;     Strasse           : String[46];
;     Hausnummer        : String[10];
;     HausnummerZusatz  : String[20];
;     Land              : String[3];
;     PLZ               : String[5];
;     Ort               : String[70];
;     Vorwahl           : String[10];
;     TelZusatz         : String[15];
;     Telefon           : String[20];
;   End;
;
Structure TDLLEintrag
  Markiert.c
  Titel.c[5]
  Adel.c
  NameVorsatz.c
  NameZusatz.c
  Geschlecht.c
  Vorname.s{30}
  Anrede.s{10}
  Name.s{120}
  Zusatz.s{120}
  Ortsteil.s{40}
  Strasse.s{46}
  Hausnummer.s{10}
  HausnummerZusatz.s{20}
  Land.s{3}
  PLZ.s{5}
  Ort.s{70}
  Vorwahl.s{10}
  Telzusatz.s{15}
  Telefon.s{20}
EndStructure

Global Res.TDLLEintrag
Global *Start = @Res
Global *Start
Global Count.l
Global *Count = @Count
Global Such.s = "090819628"
Global *Such = @Such

If OpenLibrary(0,"C:\Program Files\klickIdent Frühjahr 2009\rufid.dll")
  *SucheTelefonnummer = GetFunction(0,"SucheTelefonnummer") 
  *UseVersion = GetFunction(0,"UseVersion")
  Debug *SucheTelefonnummer
  Debug *UseVersion

  Debug *start
 
  CallFunctionFast(*UseVersion,1)
  CallFunctionFast(*SucheTelefonnummer,*Such,@Res,*Count)
  Debug *start
 
  If ExamineLibraryFunctions(0)
    While NextLibraryFunction()
      Debug LibraryFunctionName()
    Wend
  EndIf
EndIf

Repeat 
ForEver
User avatar
idle
Always Here
Always Here
Posts: 5995
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Need help Delphi/Pascal to Pure

Post by idle »

The function is returning a pointer to an array of the record Tdlleintrag
so assuming it's just a memory buffer
you could try this

Code: Select all


Structure TDLLEintrag
     Markiert.i ;         : Boolean; ;what size is boolean in delphi?
;     Titel             : TitelArray;   ;array of 5 bytes ? 
;     Adel              : Byte;
;     NameVorsatz       : Byte;
;     NameZusatz        : Byte;
; 
;     Geschlecht        : Byte;
;     Vorname           : String[30];
;     Anrede            : String[10];
;     Name              : String[120];
;     Zusatz            : String[120];
;     Ortsteil          : String[40];
;     Strasse           : String[46];
;     Hausnummer        : String[10];
;     HausnummerZusatz  : String[20];
;     Land              : String[3];
;     PLZ               : String[5];
;     Ort               : String[70];
;     Vorwahl           : String[10];
;     TelZusatz         : String[15];
;     Telefon           : String[20];
EndStructure 

Structure TDLLArray 
   item.TDLLEintrag[0]; 
EndStructure    

Prototype  SucheTelefonnummer(such.s,*res.Integer,*count.Integer) 
Global  SucheTelefonnummer. SucheTelefonnummer
Global res,count, *dllArray.TDLLArray 


SucheTelefonnummer = GetFunction(0,"SucheTelefonnummer") 

SucheTelefonnummer("090819628",*dllArray,@count)

 For co = 1 To Count
    *dllArray\item[co]\Markiert 
    
    ;    ListBox1.Items.Add( ETemp^[co].Name + #32 + ETemp^[co].Vorname + #32 +
;                        ETemp^[co].Vorwahl + '-' + ETemp^[co].Telefon );
Next ;   End;


Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply