Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-08

Changing Dataset.RecNo to use safer technique of bookmarks (TDbf database files)]]

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter E Williams

Hi Lazarus List and Alvaro,

Below is the reply to this message from my friend Alvaro in Spain, who is a part-time Delphi programmer.

On Tue, Aug 31, 2010 at 6:03 AM, Peter E Williams
Hi Alvaro, forwarded below is another yet to be answered post to the

Lazarus

programmers list. I would appreciate your thoughts on it. The

techniques

Show quoted text 10 lines
for solving this problem are identical in Lazarus and Delphi. Best Regards, PEW Hobart, Tasmania, Australia Hi All, A few months ago I posted some messages about converting my

dBase code

(in Delphi) to lazarus. I was advised that I should NOT use Dataset.RecNo but instead I should use bookmarks. Can someone

please

Show quoted text 17 lines
advise me how to rewrite: with Hexx_Data_DBF.FieldDefs do Hexx_Data_DBF_RecNo := Dataset.RecNo; to use the safer method of using bookmarks??? type { Thxboard } Thxboard = class(TForm) Hexx_Data_DBF: TDbf; var TraceFile_DBF_RecNo, Hexx_Data_DBF_RecNo : integer;

[...]

         // here I have the Hexx_Data_DBF file open and begin to loop

through it in a while loop.

Show quoted text 6 lines
while (not Hexx_Data_DBF.EOF) and not found do begin if (pattern_is_db_current(pattern1)) then begin save_options(pattern1); found := true;
                 // here I save the RecNo in a variable
with Hexx_Data_DBF.FieldDefs do Hexx_Data_DBF_RecNo := Dataset.RecNo;
                 // the close the database
close_db; if trace_moves then begin
                     // open a different TDbf file (Trace_File)
open_trace_file; With Trace_File_DBF do try
                       // go to the RecNo of the saved Trace_File's
variable
with Trace_File_DBF.FieldDefs do Dataset.RecNo := (TraceFile_DBF_RecNo);
                       // save the Hexx_Data_DBF's RecNo into the
Trace_File
FieldByName('record_no' ).AsInteger := Hexx_Data_DBF_RecNo;
                     // hmmm.... not sure whether I should be using
finally or except here.
Show quoted text 7 lines
//finally except showmessage( 'An exception occured in write_updated_pattern - writing to trace file.'); close_trace_file; end; end;
                 // reopen the Hexx_Data_DBF file
open_db;
                 // and the go back to the RecNo saved in the variable
with Hexx_Data_DBF.FieldDefs do Dataset.RecNo := (Hexx_Data_DBF_RecNo); end;
             // then use the Next procedure to continue looping through
the DBF datafile
Show quoted text 21 lines
Hexx_Data_DBF.Next; end; [...] Alvaro GP wrote: Hi Peter I never used bookmarks when I programmed in Delphi. Some people say that you shouldn't use RecNo because if you ever upscale your application to a SQL database, in the world of SQL servers there isn't the concept of "record number" but instead you browse the found records using a "Next" method repeatedly until there isn't any new records to read. If you have no intention to use SQL databases, you can safely continue using RecNo. -- Alvaro GP Lite Applications www.liteapplications.com
Proudly developing Quality Cross Platform Open Source Games Since 1970 with a Commodore PET 4016 with 16 KRAM http://pews-freeware-games.org (<--- brand new)

Reply by email

Maik Wojcieszak
to Peter E Williams

Hi,

I am working with

Lazarus IDE v0.9.28.2 Beta
MS Windows XP Prof DE sp3
FPC Version 2.2.4

I try do dynmaically load a dll during initialization phase. This can cause exceptions if the dll is not available or
the interface is not matching. Raising an exception at this point causes my application to terminate without any message.

Using "ShowMessage" is not possible. How can I inform the user about the problem before terminating ?

Thanks in advance
Maik

Reply by email

waldo kitty
to Maik Wojcieszak
Maik Wojcieszak wrote 15 lines
Hi, I am working with Lazarus IDE v0.9.28.2 Beta MS Windows XP Prof DE sp3 FPC Version 2.2.4 I try do dynmaically load a dll during initialization phase. This can cause exceptions if the dll is not available or the interface is not matching. Raising an exception at this point causes my application to terminate without any message. Using "ShowMessage" is not possible. How can I inform the user about the problem before terminating ?

isn't there a way to check that the dll is available before attempting to load it?

i don't know what to possibly do or suggest about the interface not matching...

Reply by email

Maik Wojcieszak
to waldo kitty

I've found a solution the works for windows.

//----------------------------------------------
// show a message and terminate the application
//----------------------------------------------
procedure InitError(amsg : AnsiString);
begin
   MessageBox(0,PChar(amsg),'sidex dll error',MB_ICONERROR);
   Halt(1); // terminate application
end;

This works for me now in windows. I need to develop it maybe while porting to Linux and MacOSx.
Only the direct windows API call works here, because the application is not initilized at this point.
A conditional compile to use a writeln for console application might be useful too.

Show quoted text 32 lines
On 8/31/2010 02:49, Maik Wojcieszak wrote: > Hi, > > I am working with > > Lazarus IDE v0.9.28.2 Beta > MS Windows XP Prof DE sp3 > FPC Version 2.2.4 > > I try do dynmaically load a dll during initialization phase. This can > cause > exceptions if the dll is not available or > the interface is not matching. Raising an exception at this point > causes my > application to terminate without any message. > > Using "ShowMessage" is not possible. How can I inform the user about > the problem > before terminating ? isn't there a way to check that the dll is available before attempting to load it? i don't know what to possibly do or suggest about the interface not matching... -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email