#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13

    Simple DLL problem


    I don't know where I am going wrong with a DLL I'm trying to write.
    Basically I want to read a line in a csv file and explode the different it so I can display the reslts in different text boxes.
    So the following is the DLL which splits the csv file up.

    Code:
    library collexconv;
    
    uses
      ShareMem,
      SysUtils,
      Classes;
    
     var
     StrNum: TStringList;
    
    {$R *.res}
    
    Function ExtNum(S: String): String; stdcall;
    begin
    StrNum := TStringList.Create;
    StrNum.Delimiter := ',';
    StrNum.DelimitedText := S;
    StrNum.Free;
    Result := StrNum.Strings[0];
    Result := copy(Result,5,7);
    end;
    
    Function DateOfCall (S: String): String; stdcall;
    Begin
    StrNum := TStringList.Create;
    StrNum.Delimiter := ',';
    StrNum.DelimitedText := S;
    StrNum.Free;
    Result := StrNum.Strings[1];
    end;
    Function SQLDateOfCall (S: String): String; stdcall;
    Begin
    StrNum := TStringList.Create;
    StrNum.Delimiter := ',';
    StrNum.DelimitedText := S;
    StrNum.Free;
          Result := '20'+copy(StrNum.Strings[1],7,2)+'-'+copy(StrNum.Strings[1],4,2)+'-'+copy(StrNum.Strings[1],1,2);
    end;
    
    Function TimeOfCall (S: String): String; stdcall;
    Begin
    StrNum := TStringList.Create;
    StrNum.Delimiter := ',';
    StrNum.DelimitedText := S;
    StrNum.Free;
    Result := copy(StrNum.Strings[2],1,2)+':'+copy(StrNum.Strings[2],3,2)+':'+copy(StrNum.Strings[2],5,2);
    end;
    
    
    exports
    ExtNum,DateOfCall, SQLDateOfCAll;
    end.
    and this is the program trying to access and send the string.

    Code:
    unit importcheck;
    
    interface
    
    uses
      ShareMem, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
        Function ExtNum (S: String): String; stdcall; external 'collexconv.dll';
        Function DateOfCall (S: String): String; stdcall; external 'collexconv.dll';
        Function SQLDateOfCall (S: String): String; stdcall; external 'collexconv.dll';
    
    type
      TForm1 = class(TForm)
        CdrImportEdit: TEdit;
        CdrButtonOk: TButton;
        Button2: TButton;
        Edit2: TEdit;
        Edit3: TEdit;
        Edit4: TEdit;
        CdrOpenDialog: TOpenDialog;
    
        procedure Button2Click(Sender: TObject);
        procedure CdrButtonOkClick(Sender: TObject);
    
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
        CdrText: Textfile;
      Buffer1: String;
    
      Exten: String;
      CallDay : String;
      SQLDate : String;
    
    
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
     if CdrOpenDialog.Execute then
     CdrImportEdit.Text := CdrOpenDialog.FileName;
    end;
    
    procedure TForm1.CdrButtonOkClick(Sender: TObject);
    begin
       CdrButtonOK.Enabled := False;
        CdrImportEdit.Enabled := False;
    
    
        Assignfile(CdrText, CdrImportEdit.Text);
        Reset(CdrText);
        while not EOF(CdrText) do begin
        ReadLn (CdrText, Buffer1);
        end;
        Reset(CdrText);
        Index := 0;
    
    //loop though each line of text
            while not EOF(CdrText) do begin
            ReadLn (CdrText, Buffer1);
    
                    Exten := ExtNum(buffer1);
                    CallDay := DateOfCall(buffer1);
                    SQLDate := SQLDateofCAll(buffer1);
    
                    edit2.Text := Exten;
                    edit3.Text := DateOfCall;
                    edit4.Text := SQLDateOfCall;
            end;
    end;
    
    end.
    Anyway I get the following error message:
    access violation at address 00000000

    Any Ideas?
    Last edited by lloydie-t; September 25th, 2004 at 07:50 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    England
    Posts
    952
    Rep Power
    14
    Code:
    Function ExtNum(S: String): String; stdcall;
    begin
    StrNum := TStringList.Create;
    StrNum.Delimiter := ',';
    StrNum.DelimitedText := S;
    Result := StrNum.Strings[0];
    Result := copy(Result,5,7);
    StrNum.Free;
    end;
    The Free method deallocates the memory associated with an object so it should be the last method you call in each of the functions of the DLL.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    Did'nt see that one coming. Thanks RossM

IMN logo majestic logo threadwatch logo seochat tools logo