
September 25th, 2004, 08:47 AM
|
|
Contributing User
|
|
Join Date: May 2002
Location: UK
Posts: 523

Time spent in forums: 1 Day 17 h 3 m 13 sec
Reputation Power: 7
|
|
|
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 08:50 AM.
|