Solved

IndexFieldNames in my own component

Posted on 1998-02-07
5
217 Views
Last Modified: 2012-05-04
Hi

I am using D1 with Windows 3.11

I am creating a data aware component, and I need to add the property IndexFieldNames.  I know that the TTable to which it will be attached has this property, but my component needs to have two different indexes.  I have assumed that the TFieldDataLink has a relevant property, but I cannot find any help on it.

How do I add the property to my component so that it behaves the same way as it does in the TTable component?

Any help most appreciated.
0
Comment
Question by:jdthedj
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358571
What about this?

(fDataLink.DataSource.DataSet as ttable).IndexFieldNames

Never tried out, but maybe...

Regards,Zif.

0
 
LVL 3

Author Comment

by:jdthedj
ID: 1358572
Hi ZifNab - thanks for replying

I tried that first, and it works OK at runtime, but I can't get it to work in Design mode - it tells me that the Dataset is not available.  I think that has something to do with the order in which things are initialised within the Component, but I don't know how to force different bits to initialise before others.

0
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 1358573
Hi jdthedj,
I guess I got it, pffff. found something in the help-file. It's made it in D2, so I don't know if it works under D1. But let me know!!

Put a table, datasource and button on the form, copy then this source. Linke table & datasource, etc...

Code can look some messy, sorry.  
unit unit1;

                      interface

                      uses
                        Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
                        StdCtrls, DB, Grids, DBGrids, DBTables,
                        dbitypes;

                      type
                        TForm1 = class(TForm)
                          Table1: TTable;
                                          DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Button2: TButton;

    procedure Button2Click(Sender: TObject);
                        private
                          { Private declarations }
                        public
                          { Public declarations }
                        end;

                      var
                        Form1: TForm1;


                      implementation

                      {$R *.DFM}

                      uses dbiprocs;

                      procedure TForm1.Button2Click(Sender: TObject);
procedure ShowIndexDescs(ds: TDataSet);
const
  IDXStr = '%sIndex name: %s. Number of fields in key: %d'#13#10;
var
  CurProp: CURProps;
  pIndexDesc, pTmpMem: pIdxDesc;
  i, MemSize: integer;
  ShowString, IDXName: string;
begin
  Check(DbiGetCursorProps(ds.Handle, CurProp));
  MemSize := CurProp.iIndexes * sizeof(IDXDesc);
  pIndexDesc := AllocMem(MemSize);
  try
    pTmpMem := pIndexDesc;
    Check(DbiGetIndexDescs(ds.Handle, pIndexDesc));
    i := 0;
    ShowString := '';

    while (i < curProp.iIndexes) do begin
      with pTmpMem^ do begin
        // primary index does not have a name for PARADOX tables }
        if bPrimary and (StrComp(curProp.szTableType, szParadox) = 0) then
          IDXName := 'Primary'
        else
          IDXName := szName;
        ShowString := Format(IDXStr, [ShowString, IDXName, iFldsInKey])
      end;
      // increment pointer to the next record
      inc(pTmpMem);
      inc(i);
    end;
  finally

    FreeMem(pIndexDesc, MemSize);
    ShowMessage(ShowString);
  end;
end;

                      begin
                       ShowIndexDescs(DBGrid1.DataSource.DataSet);
                      end;

end.

for your component, use fdatalink.datasource.dataset instead of dbgrid.datasource.dataset
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1358574
Hi Zif - we meet again.  The code didn't work quite as it was written, but it gave me a good start, and I have managed to do what I need to do.  Thanx
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358575
Great! c.u. Zif.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now