#1 2017-04-14 12:07:50

lagodny
Member
Registered: 2015-01-28
Posts: 50

Propose to add the implementation for sftTID in mORMotUIEdit

Sometimes it is usefull to show a common edit dialog for any TSQLRecord.
TRecordEditForm allows to do it easily. But it doesn't work with TRecordReferenceToBeDeleted properrties. I propose to fix it.

procedure TRecordEditForm.SetRecord
....
      if ((P.SQLFieldType in [ // must match "case SQLFieldType of" below
        // -- sftTID 
          sftRecord, {sftTID, }sftBlob, sftBlobDynArray, sftBlobCustom, sftUTF8Custom,
        //
....
          // ++ sftTID
          sftTID:
          if aClient<>nil then begin
            // ID field (TSQLRecord descendant) is handled by a TComboBox component
            // with all possible values of the corresponding TSQLRecord descendant
            IDClass := TSQLRecordClass((P as TSQLPropInfoRTTITID).RecordClass);
            CB := TComboBox.Create(Scroll);
            CB.Parent := Scroll; // need parent now for CB.Items access
            CB.Style := csDropDownList;
            aID := GetInt64(pointer(aValue));
            with IDClass.RecordProps do
            if MainField[true]>=0 then begin
              aClient.OneFieldValues(IDClass,Fields.List[MainField[true]].Name,
                '',CB.Items,@aID);
              CB.ItemIndex := aID; // @aID now contains the found index of aID
            end;
          end;
          //


procedure TRecordEditForm.BtnSaveClick(Sender: TObject);
....
    if C.InheritsFrom(TComboBox) then begin
      SetIndex := CB.ItemIndex;
      case P.SQLFieldType of
        sftEnumerate:
          if SetIndex>=0 then begin
            P.SetValue(Rec,pointer(Int32ToUTF8(SetIndex)),false);
            Include(ModifiedFields,FieldIndex);
          end;
        // + sftTID
        sftID, sftTID: begin
        //
          if SetIndex<0 then
            aID := 0 else
            aID := PtrInt(CB.Items.Objects[SetIndex]);
          P.SetValue(Rec,pointer(Int64ToUTF8(aID)),false);
          Include(ModifiedFields,FieldIndex);
        end;
      end;
    end else

Offline

Board footer

Powered by FluxBB