Delphi DLL problems
From: Zebedee (abuse_at_127.0.0.1)
Date: 02/27/04
- Next message: Maarten Wiltink: "Re: CLX compatibility with VLC : Align in a form"
- Previous message: AlanGLLoyd: "Re: Mapping Into VCL"
- Next in thread: Duncan McNiven: "Re: Delphi DLL problems"
- Reply: Duncan McNiven: "Re: Delphi DLL problems"
- Reply: Rob Kennedy: "Re: Delphi DLL problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 27 Feb 2004 20:08:11 -0000
I'm trying to run a Delphi DLL I've written. I'm not sure I've written it
correctly. Can somebody have a look and tell me where I'm going wrong? It's
probably something very simple. This is the calling code:
procedure TAgencyController.Button6Click(Sender: TObject);
var LibHandle :THandle;
begin
LibHandle := LoadLibrary('DatabaseP.dll');
if LibHandle = 0 then ShowMessage('Aaarggghh');
TDataBase.LoadLibrary('');
FreeLibrary(LibHandle);
end;
This is the DLL code.
library DatabaseP;
uses
SysUtils,Classes,DateUtils;
{$R *.res}
// procedure list
Type
TDataBase = class(TObject)
{$ifdef DataBase}
public
Function LoadDataBase(LocationAndName:ShortString):Boolean;
Procedure SaveDataBase(LocationAndName: ShortString);
Procedure AddNew(EmailAddress:ShortString);
Procedure Delete(EmailAddress:ShortString);
Procedure Return(EmailAddress:ShortString; var FirstMailed, FirstReplied,
LastMailed, LastReplied,
FirstCVSent, LastCVSent : ShortString; TimesMailed, TimesReplied,
SillyReplies : Integer; Deleted:Boolean);
Procedure MarkMailed(EmailAddress:ShortString);
Procedure MarkCVSent(EmailAddress:ShortString);
Function HowManyRecords: Integer;
Function HowManyDeleted: Integer;
Function NextDeleted: ShortString;
Function HowManyNotCVd: Integer;
Function HowManyNotReplied: Integer;
Function HowManyNotContacted: Integer;
Function AddressPresent(EmailAddress :ShortString): Boolean;
Function CheckPresentOrDeleted(EmailAddress : ShortString): Boolean;
Function ClearOutDeleted : Integer;
Function IsAddressPresent(EmailAddress: ShortString): boolean;
Function IsAddressDeleted(EmailAddress: ShortString): boolean;
Procedure Rewind;
// return records
Procedure NextFull(EmailAddress:ShortString; var FirstMailed, FirstReplied,
LastMailed, LastReplied,
FirstCVSent, LastCVSent : ShortString; TimesMailed, TimesReplied,
SillyReplies : Integer; Deleted:Boolean);
Function NextNotFirstMailed : ShortString; // returns email address or ''
for no more
Function NextNotFirstCV: ShortString; // returns email address or '' for no
more
Function NextMailedButNotReplied: ShortString; // returns address of people
emailed but who haven't replied
Function NextSevenDaySilence: ShortString;// returns address of people
who've not responded for 7 days.
Function NextFourteenDaySilence: ShortString;// returns address of people
who've not responded for 14 days
Function NextTwentyOneDaySilence: ShortString;// returns address of people
who've not responded for 21 days
Function NextMonthSilence: ShortString;// returns address of people who've
not responded for a month
Function NextTwoMonthSilence: ShortString;// returns address of people
who've not responded for two months
Function NextThreeMonthSilence: ShortString;// returns address of people
who've not responded for two months
Function NextFourMonthSilence: ShortString;// returns address of people
who've not responded for two months
Function NextFiveMonthSilence: ShortString;// returns address of people
who've not responded for two months
Function NextSixMonthSilence: ShortString;// returns address of people
who've not responded for two months
end;
var
DateOfFirstSendingList, DateOfLastSendingList, NumberOfSendingsList,
DateOfFirstReplyList,
DateOfLastReplyList, NumberOfRepliesList, DateOfLastCVSentList,
DateOfFirstCVSentList,
NumberofCVsSentList, NoOfSillyRepliesList, EmailAddressList, DeletedList:
TStringList;
FirstAddressListCounter : integer;
// actual procedures
Function TDataBase.LoadDataBase(LocationAndName:ShortString):boolean;
var
MailingList : Packed Record
DateOfFirstSending : Double;
DateOfLastSending : Double;
NumberOfSendings : integer;
DateOfFirstReply : Double;
DateOfLastReply : Double;
NumberOfReplies : integer;
DateOfLastCVSent : Double;
DateOfFirstCVSent : Double;
NumberofCVsSent : integer;
NoOfSillyReplies : integer;
EmailAddress : ShortString;
RecordDeleted : Boolean;
end;
MyDataFile : TFileStream;
TotalCount : Integer;
DataListCount: Integer;
FileLength : integer;
begin
DateOfFirstSendingList := TStringList.Create;
DateOfLastSendingList := TStringList.Create;
NumberOfSendingsList := TStringList.Create;
DateOfFirstReplyList := TStringList.Create;
DateOfLastReplyList := TStringList.Create;
NumberOfRepliesList := TStringList.Create;
DateOfLastCVSentList := TStringList.Create;
DateOfFirstCVSentList := TStringList.Create;
NumberofCVsSentList := TStringList.Create;
NoOfSillyRepliesList := TStringList.Create;
EmailAddressList := TStringList.Create;
DeletedList := TStringList.Create;
if Not FileExists(LocationAndName) then
begin
Result := False;
Exit;
end;
// so the datafile exists
MyDataFile := TFileStream.Create(LocationAndName,fmOpenRead);
// load the existing database
TotalCount := 0;
DataListCount := 0;
FileLength := MyDataFile.Size;
while DataListCount < FileLength do
begin
TotalCount := TotalCount + 1;
MyDataFile.Position := DataListCount;
MyDataFile.ReadBuffer(MailingList,sizeof(MailingList));
DataListCount := DataListCount + sizeof(MailingList);
EmailAddressList.Add(MailingList.EmailAddress);
NumberOfSendingsList.Add(IntToStr(MailingList.NumberOfSendings));
if MailingList.DateOfLastSending = 0 then DateOfLastSendingList.Add('-')
else
DateOfLastSendingList.Add(DateToStr(ModifiedJulianDateToDateTime(MailingList
.DateOfLastSending)));
if MailingList.DateOfFirstSending = 0 then
DateOfFirstSendingList.Add('-') else
DateOfFirstSendingList.Add(DateToStr(ModifiedJulianDateToDateTime(MailingLis
t.DateOfFirstSending)));
if MailingList.DateOfLastReply = 0 then DateOfLastReplyList.Add('-') else
DateOfLastReplyList.Add(DateToStr(ModifiedJulianDateToDateTime(MailingList.D
ateOfLastReply)));
if MailingList.DateOfFirstReply = 0 then DateOfFirstReplyList.Add('-')
else
DateOfFirstReplyList.Add(DateToStr(ModifiedJulianDateToDateTime(MailingList.
DateOfFirstReply)));
NumberOfRepliesList.Add(IntToStr(MailingList.NumberOfReplies));
if MailingList.DateOfLastCVSent = 0 then DateOfLastCVSentList.Add('-')
else
DateOfLastCVSentList.Add(DateToStr(ModifiedJulianDateToDateTime(MailingList.
DateOfLastCVSent)));
if MailingList.DateOfFirstCVSent = 0 then DateOfFirstCVSentList.Add('-')
else
DateOfFirstCVSentList.Add(DateToStr(ModifiedJulianDateToDateTime(MailingList
.DateOfFirstCVSent)));
NumberofCVsSentList.Add(IntToStr(MailingList.NumberofCVsSent));
NoOfSillyRepliesList.Add(IntToStr(MailingList.NoOfSillyReplies));
DeletedList.Add(BoolToStr(MailingList.RecordDeleted));
end;
MyDataFile.Free;
Result := True;
end;
Procedure TDataBase.SaveDataBase(LocationAndName: ShortString);
var
MailingList : Packed Record
DateOfFirstSending : Double;
DateOfLastSending : Double;
NumberOfSendings : integer;
DateOfFirstReply : Double;
DateOfLastReply : Double;
NumberOfReplies : integer;
DateOfLastCVSent : Double;
DateOfFirstCVSent : Double;
NumberofCVsSent : integer;
NoOfSillyReplies : integer;
EmailAddress : ShortString;
RecordDeleted : Boolean;
end;
MyDataFile : TFileStream;
Count : Integer;
begin
MyDataFile := TFileStream.Create(LocationAndName,fmCreate);
// now go through TStringLists and save data
for Count := 0 to EmailAddressList.Count -1 do
begin
if DateOfFirstSendingList.Strings[Count] = '-' then
MailingList.DateOfFirstSending := 0
else MailingList.DateOfFirstSending :=
DateTimeToModifiedJulianDate(StrToDate(DateOfFirstSendingList.Strings[Count]
));
if DateOfLastSendingList.Strings[Count] = '-' then
MailingList.DateOfLastSending := 0
else MailingList.DateOfLastSending :=
DateTimeToModifiedJulianDate(StrToDate(DateOfLastSendingList.Strings[Count])
);
MailingList.NumberOfSendings :=
StrToInt(NumberOfSendingsList.Strings[Count]);
if DateOfFirstReplyList.Strings[Count] = '-' then
MailingList.DateOfFirstReply := 0
else MailingList.DateOfFirstReply :=
DateTimeToModifiedJulianDate(StrToDate(DateOfFirstReplyList.Strings[Count]))
;
if DateOfLastReplyList.Strings[Count] = '-' then MailingList.DateOfLastReply
:= 0
else MailingList.DateOfLastReply :=
DateTimeToModifiedJulianDate(StrToDate(DateOfLastReplyList.Strings[Count]));
MailingList.NumberOfReplies :=
StrToInt(NumberOfRepliesList.Strings[Count]);
if DateOfFirstCVSentList.Strings[Count] = '-' then
MailingList.DateOfFirstCVSent := 0
else MailingList.DateOfFirstCVSent :=
DateTimeToModifiedJulianDate(StrToDate(DateOfFirstCVSentList.Strings[Count])
);
if DateOfLastCVSentList.Strings[Count] = '-' then
MailingList.DateOfLastCVSent := 0
else MailingList.DateOfLastCVSent :=
DateTimeToModifiedJulianDate(StrToDate(DateOfLastCVSentList.Strings[Count]))
;
MailingList.NumberofCVsSent :=
StrToInt(NumberofCVsSentList.Strings[Count]);
MailingList.NoOfSillyReplies :=
StrToInt(NoOfSillyRepliesList.Strings[Count]);
MailingList.EmailAddress := EmailAddressList.Strings[Count];
MailingList.RecordDeleted := StrToBool(DeletedList.Strings[Count]);
MyDataFile.Write(MailingList,sizeof(MailingList));
end;
MyDataFile.Free;
// now free the memory
DateOfFirstSendingList.Free;
DateOfLastSendingList.Free;
NumberOfSendingsList.Free;
DateOfFirstReplyList.Free;
DateOfLastReplyList.Free;
NumberOfRepliesList.Free;
DateOfLastCVSentList.Free;
DateOfFirstCVSentList.Free;
NumberofCVsSentList.Free;
NoOfSillyRepliesList.Free;
EmailAddressList.Free;
DeletedList.Free;
end;
exports
// procedures to export
DataBase;
{$endif};
end.
-- Yours Zebedee (Claiming asylum in an attempt to escape paying his debts to Dougal and Florence)
- Next message: Maarten Wiltink: "Re: CLX compatibility with VLC : Align in a form"
- Previous message: AlanGLLoyd: "Re: Mapping Into VCL"
- Next in thread: Duncan McNiven: "Re: Delphi DLL problems"
- Reply: Duncan McNiven: "Re: Delphi DLL problems"
- Reply: Rob Kennedy: "Re: Delphi DLL problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]