Skip to main content
gamedev.net
🔒 Locked

Buttonclicking Delphi

Started by _Madman_ 5 replies 450+ views
Original Post
_Madman_
_Madman_
I''m C programmer, but currently I have one project to finish in Delphi. I need to create a database (Paradox) & perform some sort of calculations on it & output data as standart strings. I have created program that connects me to this paradox database & outputs all info I need + editing stuff & so on. The problem arises when I need to read all the stuff from table => every cell of every row. I have spent about week & still cant find any lo-level f/n''s to do that. All I need is to read all the cells to strings, can someone PLEASE help me? Sometimes it seems that it''ll be easier to write DB functions in C & try to export them to delphi by DLL''s. GRRRRRRR......... :''( ______________________________ Madman
______Madman
Michalson
Michalson
You''ll have to explain what API/method you are using to connect to the Paradox database. If you are under the impression that you need to use another language then you have obviously missed some important information, or you have chosen some extremely special, extremely limited API that no one has ever heard of to use in Delphi, and a normal API in C. If this kind of difficulty is happening often you should probably invest more time in learning Delphi, it is not a limited language like VB, you do not need hacks or C DLLs to do anything.
_Madman_
_Madman_
I''m using Borland Delphi 5 with all it''s bells & whistles. I connect DB using BDE administrator & I am creating it with the help of Database desktop. Then in program I''m using datasource & table components for output, editing. DB is staticaly tied to my program.
That Borland Database Engine is driving me crazy

______________________________
Madman
______Madman
Michalson
Michalson
If you don''t like it, don''t use it. There are plenty of other ways to get at a database. You use Borland''s ADO components or import the MS ActiveX ADO components and do SQL from there.

With BDE I assume you have some decendent of a TDataSet object like a Table or Query either created in your code or made using the drag and drop part IDE.


var I:Integer;
S:TStringList;
begin
//Table 1 is connect to some database

Table1.TableName:=''blah'';
Table1.Filtered:=False;
Table1.Open;
S:=TStringList.Create;
while not Table1.Eof do
begin
for I:=0 to Table1.Fields.Count-1 do
S.Add(Table1.Fields.Fields[I].DisplayName+'':''+Table1.Fields.Fields[I].AsString);
Table1.Next;
end;
S.SaveToFile(''blah'');
S.Free;
Table1.Close;
end;

_Madman_
_Madman_
Thanks for assistance I''ll try that.

______________________________
Madman
______Madman
_Madman_
_Madman_
It worked, I''d have never imagined that so much can be done through table''s subclass field I guess I wouldn''t have found that. Maybe I''ll even start to love Delphi some day

Anyway, whats happening after all table is parsed, as far as I understand table is reporting EOF & stays this way, so if I execute this code once more I get nothing but direct termination of while loop. How can I reset eof status & current location?

BTW, is there something like formated input in delphi sscanf("%s;%s",&a,&b); ? And how dll importing syntax looks like here, I doubt ther''s exactly the same synatax as in C __declspec(dllimport)................


______________________________
Madman
______Madman
Alimonster
Alimonster
quote:
Original post by _Madman_
It worked, I'd have never imagined that so much can be done through table's subclass field I guess I wouldn't have found that. Maybe I'll even start to love Delphi some day

Anyway, whats happening after all table is parsed, as far as I understand table is reporting EOF & stays this way, so if I execute this code once more I get nothing but direct termination of while loop. How can I reset eof status & current location?

BTW, is there something like formated input in delphi sscanf("%s;%s",&a,&b); ? And how dll importing syntax looks like here, I doubt ther's exactly the same synatax as in C __declspec(dllimport)................

Try using YourQuery.First to get back to the first record. For the second question, you can use the Format function. Look up Format and/or Format Strings in the help files (the easiest way is to type each into the code editor and hit F1 with the cursor inside the words). It works much like printf, e.g. "MyString := Format('Blah blah %d asdf %d', [IntVar1, IntVar2]);"

EDIT: Oh, for input. Never mind then... I'm sure there's a way but I can't think of it.

The DLL importing things are easy enough -- you declare a function as normal and then use "external 'nameofdll.dll'". Look up the external keyword. You may have to add in "stdcall" as the calling convention:

procedure Something; external 'somefile.dll';
procedure Another; stdcall; external 'somefile.dll';


It depends on how it was declared for the dll. You can also declare function pointers and load the procs at run-time with LoadLibrary et al. It's also possible to rename functions in DLLs when using them -- it's all shown in the help files though.

As a free tip: use the high, low and/or length functions when dealing with arrays. This can save a world of hurt and severely reduces chances of array out-of-bounds (esp. if you temporarily enable range-checking for debugging). E.g.

var
i: Integer;
Blah: array[0..19] of Integer;
begin
for i := Low(Blah) to High(Blah) do
Blah[i ] := ...
end;


Finally, install GExperts because it rocks.

[edited by - Alimonster on September 1, 2003 4:07:30 AM]

[edited by - Alimonster on September 1, 2003 4:14:23 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.