Italian community of Lazarus and Free Pascal

Programmazione => Generale => Topic aperto da: xinyiman - Ottobre 29, 2019, 12:14:50 pm

Titolo: Domandina stupida stupida
Inserito da: xinyiman - Ottobre 29, 2019, 12:14:50 pm
Ciao ragazzi, non ricordo come trasformare un TFieldType (esempio ftString, ftSmallInt, ecc) in stringa e viceversa. Qual'è già la sintassi?
Titolo: Re:Domandina stupida stupida
Inserito da: nomorelogic - Ottobre 29, 2019, 12:53:16 pm
GetEnumName

https://www.freepascal.org/docs-html/rtl/typinfo/getenumname.html
Titolo: Re:Domandina stupida stupida
Inserito da: xinyiman - Ottobre 29, 2019, 01:49:22 pm
Grazie Nomore. Mi hanno suggerito anche questa soluzione alternativa

Codice: [Seleziona]
    uses db;
     
    function FieldTypeToStr(aFieldType: TFieldType): String;
    begin
      Exit(Fieldtypenames[aFieldType]);
    end;
     
    function StrToFieldType(aString: String): TFieldType;
    var
      ft: TFieldType;
    begin
      aString := LowerCase(aString);
      Delete(aString, 1, 2);
      for ft := Low(TFieldType) to High(TFieldType) do
        if aString = LowerCase(Fieldtypenames[ft]) then
          Exit(ft);
      Result := ftUnknown;
    end;