Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 25th, 2004, 08:47 AM
lloydie-t lloydie-t is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Location: UK
Posts: 523 lloydie-t User rank is Private First Class (20 - 50 Reputation Level)lloydie-t User rank is Private First Class (20 - 50 Reputation Level) 
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.

Reply With Quote
  #2  
Old September 25th, 2004, 01:38 PM
rossM rossM is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: England
Posts: 952 rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 23 h 38 m 44 sec
Reputation Power: 8
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.

Reply With Quote
  #3  
Old September 25th, 2004, 01:54 PM
lloydie-t lloydie-t is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Location: UK
Posts: 523 lloydie-t User rank is Private First Class (20 - 50 Reputation Level)lloydie-t User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 17 h 3 m 13 sec
Reputation Power: 7
Did'nt see that one coming. Thanks RossM

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Simple DLL problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT