Hi all,
I have TListBox that loads a string field of an SQLite database, then when you double click on each item, it goes to a separate page where other database fields corresponding to that item are loaded and displayed in other fields. Note it is a regular TListBox as I simply can't get any database-aware components to work - see my previous thread on that, which is the only topic I haven't been able to solve.
Anyway, it mostly works fine except when I delete rows - then everything gets out of whack. If I have a table like this:
Item one
Item two
Item three
Item four
And then I delete item two, double clicking on item three's entry in the TListbox will now load a blank set of data. Double clicking on item four's entry in the TListbox loads item three's data. When I open the database externally in an SQL browser, it all looks absolutely fine. There's no blank row, and the browser renders the rowids sequentially. Here is the delete code:
procedure TForm1.DeleteIssueButtonClick(Sender: TObject);
begin
if MessageDlg('', 'Do you want to delete the selected issue?', mtConfirmation,
[mbYes, mbNo],0) = mrNo
then
exit
else
UserFileConnection.Open;
UserFileTransaction.Active:= True;
UserFileSave.SQL.Text:=('DELETE FROM `Custom1` WHERE _rowid_=:RowParam;');
UserFileSave.Params.ParamByName('RowParam').Value := IssueListDisplay.ItemIndex+1;
UserFileSave.ExecSQL;
UserFileTransaction.Commit;
IssueListDisplay.Items.Delete(IssueListDisplay.ItemIndex);
end;
I won't paste the entire loading code as it's long, but this should be enough to demonstrate how I'm doing it:
procedure TForm1.GoStdProtocolBtnClick(Sender: TObject);
begin
UserFileConnection.Open;
UserFileTransaction.Active:= True;
UserFileLoad.SQL.Text:=('SELECT * FROM Custom1 WHERE _rowid_ = :RowParam');
UserFileLoad.Params.ParamByName('RowParam').Value := IssueListDisplay.ItemIndex+1;
UserFileTransaction.Commit;
UserFileLoad.Open;
IssueNameFld.Text := UserFileLoad.Fieldbyname('Issue').AsString;
IssueCommentsFld.Text := UserFileLoad.Fieldbyname('IssueComments').AsString;
// Load the other fields corresponding to this entry etc.
end;
Any thoughts? Thanks!
