Re: TClientDataset and Refresh



I tried doing that but I get a problem with indexes.
cdsNotify : Index 'Message_IdxA' not found.
I'm using a sort function as noted below:

Is there another way to do this w/o opening and closing the cds as doing
this appears to trigger off the errors.

Stephen K. Miyasato



unit sortfunctions;

interface

uses
DB, DBClient;

function SortCustomClientDataSet(DataSet: TCustomClientDataSet;
const FieldName: String): Boolean;

function SortClientDataSet(ClientDataSet: TClientDataSet;
const FieldName: String): Boolean;

implementation

uses TypInfo, PickListEdit; //TypInfo needed for RTTI GetObjectProp
//IsPublishedProp, and SetStrProp methods
//used in SortCustomClientDataSet

function SortCustomClientDataSet(DataSet: TCustomClientDataSet;
const FieldName: String): Boolean;
var
i: Integer;
IndexDefs: TIndexDefs;
IndexName: String;
IndexOptions: TIndexOptions;
Field: TField;
begin
Result := False;
//PickListEditFrm.wwKeyCombo1.Text:= ''; // reset {*
Field := DataSet.Fields.FindField(FieldName);
//If invalid field name, exit.
if Field = nil then Exit;
//if invalid field type, exit.
if (Field is TObjectField) or (Field is TBlobField) or
(Field is TAggregateField) or (Field is TVariantField)
or (Field is TBinaryField) then Exit;
//Get IndexDefs and IndexName using RTTI
if IsPublishedProp(DataSet, 'IndexDefs') then
IndexDefs := GetObjectProp(DataSet, 'IndexDefs') as TIndexDefs
else
Exit;
if IsPublishedProp(DataSet, 'IndexName') then
IndexName := GetStrProp(DataSet, 'IndexName')
else
Exit;
//Ensure IndexDefs is up-to-date
IndexDefs.Update;
//If an ascending index is already in use,
//switch to a descending index
if IndexName = FieldName + '__IdxA'
then
begin
// PickListEditFrm.wwKeyCombo1.Text:= '';
IndexName := FieldName + '__IdxD';
IndexOptions := [ixDescending];
end
else
begin
//PickListEditFrm.wwKeyCombo1.Text:= indexName;
IndexName := FieldName + '__IdxA';
IndexOptions := [];
end;
//Look for existing index
for i := 0 to Pred(IndexDefs.Count) do
begin
if IndexDefs[i].Name = IndexName then
begin
Result := True;
Break
end; //if
end; // for
//If existing index not found, create one
if not Result then
begin
DataSet.AddIndex(IndexName, FieldName, IndexOptions);
Result := True;
end; // if not
//Set the index
SetStrProp(DataSet, 'IndexName', IndexName);
end;

//This version does not require RTTI, but only
//works with ClientDataSets.
function SortClientDataSet(ClientDataSet: TClientDataSet;
const FieldName: String): Boolean;
var
i: Integer;
NewIndexName: String;
IndexOptions: TIndexOptions;
Field: TField;
begin
Result := False;
Field := ClientDataSet.Fields.FindField(FieldName);
//If invalid field name, exit.
if Field = nil then Exit;
//if invalid field type, exit.
if (Field is TObjectField) or (Field is TBlobField) or
(Field is TAggregateField) or (Field is TVariantField)
or (Field is TBinaryField) then Exit;
//Get IndexDefs and IndexName using RTTI
//Ensure IndexDefs is up-to-date
ClientDataSet.IndexDefs.Update;
//If an ascending index is already in use,
//switch to a descending index
if ClientDataSet.IndexName = FieldName + '__IdxA'
then
begin
NewIndexName := FieldName + '__IdxD';
IndexOptions := [ixDescending];
end
else
begin
NewIndexName := FieldName + '__IdxA';
IndexOptions := [];
end;
//Look for existing index
for i := 0 to Pred(ClientDataSet.IndexDefs.Count) do
begin
if ClientDataSet.IndexDefs[i].Name = NewIndexName then
begin
Result := True;
Break
end; //if
end; // for
//If existing index not found, create one
if not Result then
begin
ClientDataSet.AddIndex(NewIndexName,
FieldName, IndexOptions);
Result := True;
end; // if not
//Set the index
ClientDataSet.IndexName := NewIndexName;
end;


"Bill Todd" <no@xxxxxx> wrote in message
news:44f4c0f4$1@xxxxxxxxxxxxxxxxxxxxxxxxx
Stephen K. Miyasato wrote:

I have a TClientDataset set to a TADODataset which is set to close
(Active = False). When I do a Refresh it does not refresh the
TClientDataset. I have to manually shut don't the application then
restart it in order to get the new updates. I have the TclientDataset
set up in read-only mode.

Any resolution to the problem?

Stephen K. Miyasato

Try closing then opening the CDS.

--
Bill Todd (TeamB)


.