Work with Delphi and Access

I want to write an application using the Access database (* .mdb). I know how to connect to mdb and how to use SQL statements. My problem is that I want to put the query result in a TListView.

Any information / link / book is welcome :)

+3
source share
5 answers

Pull your result, and then pass it to the following procedure (for example):

Query.First;
While not Query.EOF do
  begin
    StrObj := tStringList.create;
    StrObj.Add(Query.FieldByname('id').asString);
    ListView.AddItem(Query.FieldByName('Title').AsString,StrObj);
    Query.Next;
  end;

This will load your list view with nodes with the name of the field name, and each node will contain a tstringlist containing all the data you want to save for each node. Personally, I would extend this and use a custom owner object, not a tStringList, but this was just an example.

+3

TListView , , (AFAIK) VCL TDBListView - , TDBGrid, TDBListView , google.

+2

ListView - Delphi. ListView , vsReport - , ( - vsList, vsIcon vsLargeIcon).

"" ( , , vsReport ), AddItem() ListView. AddItem TListItem. Caption , ( vsList, vsIcon vsLargeIcon) "" vsReport. TStringList SubItems. , SubItems, vsReport (SubItems ).

, , , TListItem. , , .

, :

DS := TSomeKindOfDataSet.Create();

try

    //Set up and open DS.

    while not DS.eof do begin

        with ListView.Items.Add() do begin

            //establish three columns for vsReport display
            Caption := DS.FieldByName('DescriptiveField').AsString;
            SubItems.Add(DS.FieldByname('AnotherColumn').AsString);
            SubItems.Add(DS.FieldByname('YetAnotherColumn').AsString);

            //Save the record PK value
            Data := Pointer(DS.FieldByname('PKColumn').AsInteger);

        end;

        DS.Next;

    end;

finally

   DS.Free;

end;

, DS, , , . DS , , .

+2

TListView. .

But Delphi provides data management tools. This will take care of connecting to the database. For most applications, this is enough.

+1
source

There are several VirtualTreeView implementations that work with databases. Here is one link , and here is the VirtualTreeView website .

+1
source

Source: https://habr.com/ru/post/1722742/


All Articles