Solved

IndexFieldNames in my own component

Posted on 1998-02-07
5
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 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