Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with FindLast command.

Status
Not open for further replies.

Goldsteen

Programmer
Oct 29, 2005
1
0
0
AW
Hello

I am a new programmer in Delphi 6, and I would like to get some assistance with a with the FindLast command.
I am trying to read each record sequentially from a file via ODBC and writing some fields from each record to new
text file sequentially as well.


Each time I run the program it gives the following error message when it reaches the "until not iseof" line.


// ******************* start of error message *******************

Project ScanPal2.exe raises exception class EOleException with message 'Either BOF or EOF is True, or the current record has been deleted.

Requested operation requires a current record'. Process stopped.

// ******************* end of error message *******************




My code is as follows:



// ******************* start of my code *******************


procedure TForm1.OutputFile1Click(Sender: TObject);
var
btnPressed : integer;
FileAttrs : integer;
txt : TextFile;
line : String;
SR : TSearchRec;
iseof : boolean;

begin
if frmSelectDS.cmboxSelDS.Text <> '' then
begin
btnpressed:= MessageDlg('Go ahead and create scanpal import file?', mtConfirmation, mbOKCancel,500);
if btnPressed = mrOk then
begin
qryScanDS.ConnectionString := 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=' + frmSelectDS.cmboxSelDS.Text;
try
begin
qryScanDS.SQL.Text := 'SELECT itemnumber, description1, category, price1, QtyOnHand FROM items';
qryScanDs.Active := true;
//tekst file aanmaken
if FileExists(Options.OutputPath.Text) then
begin
if (MessageDlg('File ' + Options.OutputPath.Text + ' exists. Overwrite?', mtConfirmation,
[mbOk, mbCancel], 0) = mrCancel) then
begin
Exit;
end;
end;
AssignFile(txt, Options.OutputPath.Text);
Rewrite(txt);

repeat
line := qryScanDS.Fields[0].text + Options.SeparationCharacter.Text + qryScanDS.Fields[1].text + Options.SeparationCharacter.Text +

qryScanDS.Fields[2].text + Options.SeparationCharacter.Text + qryScanDS.Fields[3].text + Options.SeparationCharacter.Text +

qryScanDS.Fields[4].text;
if IsDelimiter(Options.SeparationCharacter.Text, line, 0) then
begin
MessageDlg('You must use another character!', mtConfirmation, mbOKCancel,500);
if btnPressed = mrOk then
begin
exit;
end;
end;
WriteLn(txt, line);
iseof := qryScanDS.findnext();
until not iseof
end;


// ******************* end of my code *******************




I hope that someone can point out where my mistake is.



Regards,
Johan
 
If you are using a query to read your data, then you need to use the First ... Next commands.

For example:

with myQuery do begin
if active then close;
Parameters.ParamByName('id').Value := My_ID;
open;
first;
while not EOF do begin
// do something with the current record
next;
end;
end;

Hope this helps.
Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top