Hello, everybody. Please, find attached draft zmsql package of incoming version 0.1.15. New version brings:
*implemented autoincrement fields (ftAutoInc).
*Improved visibility of TDataset methods and properties.
*zmquerydataset works again with TBufDataset as ancestor (as in CodeTyphon v.4.70).
In meantime, if someone can investigate why persistent fields created with following method bring different kind of errors, such as: "Class "TStringField" not found"?
Namely, persistent fields seem to be correctly created, they are present in .lfm and are visible in object inspector, but during run-time, different errors occur...
It seems that persistent fields created through editor don't have such problems?
The idea was to enable automatic creation of all persistent fields, from previously defined fielddefs, by setting property PersistentFieldsCreated to True. Obviously, something is not OK with the following code:
procedure TZMQueryDataSet.DoCreatePersistentFieldsFromFieldDefs;
var
NewField: TField;
FieldDef: TFieldDef;
i: integer;
function FieldNameToPascalIdentifer(const AName: string): string;
var
i : integer;
begin
Result := '';
// FieldName is an ansistring
for i := 1 to Length(AName) do
if AName[i] in ['0'..'9','a'..'z','A'..'Z','_'] then
Result := Result + AName[i];
if (Length(Result) > 0) and (not (Result[1] in ['0'..'9'])) then
Exit;
if Assigned(FieldDef.FieldClass) then
begin
Result := FieldDef.FieldClass.ClassName + Result;
if Copy(Result, 1, 1) = 'T' then
Result := Copy(Result, 2, Length(Result) - 1);
end
else
Result := 'Field' + Result;
end;
function CreateFieldName(Owner: TComponent; const AName: string): string;
var
j:integer;
begin
for j := 0 to Owner.ComponentCount - 1 do
begin
if CompareText(Owner.Components[j].Name, AName) = 0 then
begin
Result := FormEditingHook.CreateUniqueComponentName(NewField);
exit;
end;
end;
Result := AName;
end;
begin
//This procedure creates PERSISTENT Fields from predefined FieldDefs.
for I:=0 to fielddefs.Count-1 do
with Fielddefs.Items[I] do begin
FieldDef := Fielddefs.Items[I];
if DataType<>ftUnknown then
begin
//Create new field and set it's unique name.
NewField:=CreateField(self.Owner); //self.Owner ---> this makes created field to be persistent and visible in object inspector.
NewField.Name := CreateFieldName(self.Owner, self.Name + FieldNameToPascalIdentifer(NewField.FieldName));
end;
//Set initial properties of the field.
NewField.FieldKind:=fkData;
NewField.SetFieldType(FieldDef.DataType);
NewField.Size:=FieldDef.Size;
end;
self.BindFields(True);
end;