Einzelnen Beitrag anzeigen

DualCoreCpu
(Gast)

n/a Beiträge
 
#1

Strin an ShortString zuweisen, wie?

  Alt 6. Nov 2019, 21:36
Hallo,

ich habe Variablen vom Typ Shortstring, an die ich nun Variableninhalte vom Typ String zuweisen will. Nun hat ja wohl ein String ein anderes Format (Größe eines Zeichens in Byte), als der ShortString.

Wie kann ich da möglichst unkompliziert einen String an eine Shortstring-Variable zuweisen. Ich brauche hierfür hauptsächlich nur das englische Alphabet, mur für MenuName könnte ich die Deutschen Umlaute noch zusätzlich gebrauchen.

Delphi-Quellcode:
type
**TMenuNameStr = array[0..31] of Ansichar;
**TProgNameStr = array[0..255] of AnsiChar;
**TDirNameStr = array[0..255] of AnsiChar;
**TCfgNameStr = array[0..29] of Ansichar;
**TOptionsStr = array[0..127] of Ansichar;
**TRegisteredCommand = class(TObject)
**private
****FMenuName: TMenuNameStr;
****FProgName: TProgNameStr;
****FDirName: TDirNameStr;
****FOptions: TOptionsStr;
****FCfgFile: TCfgNameStr;
****function GetCfgFile: ShortString;
****function GetDirName: ShortString;
****function GetMenuName: ShortString;
****function GetOptions: ShortString;
****function GetProgName: ShortString;
****procedure SetCfgFile(const Value: ShortString);
****procedure SetDirName(const Value: ShortString);
****procedure SetMenuName(const Value: ShortString);
****procedure SetOptions(const Value: ShortString);
****procedure SetProgName(const Value: ShortString);
**public
***{
* * constructor Create;
* * destructor Destroy; override;
** }

****constructor Create;
****property MenuName: ShortString read GetMenuName write SetMenuName;
****property ProgName: ShortString read GetProgName write SetProgName;
****property DirName: ShortString read GetDirName write SetDirName;
****property Options: ShortString read GetOptions write SetOptions;
****property CfgFile: ShortString read GetCfgFile write SetCfgFile;
**end;

**TCommandsList = class(TObjectList)
****property Command: TRegisteredCommand read GetCommand write SetCommand;
**end;
Wegen säterer Absicht, die Commands in einer Datei abzulegen, habe ich hier Shortstring gewählt. Wenn ich die Kommandos aber nun in einer Ini Datei ablegen will, tritt beim Wieder einlesen das Problem auf, dass ja Inifile.ReadString() einen String, nicht ShortString zurück gibt. Wie kann ich diesen String nun an ShortString zuweisen?

Delphi-Quellcode:

var
 nMenu,nPath,nProg,nConf,nOpts: String;

    nMenu := FIniFile.ReadString('Command','Menuname','');
    nPath := FIniFile.ReadString('Command','Directory','');
    nProg := FIniFile.ReadString('Command','Exename','');
    nConf := FIniFile.ReadString('Command','CfgFile','');
    nOpts := FIniFile.ReadString('Command','Options','');

    move(nMenu[1],FCommand.MenuName[1], Length(nMenu)); //??? funzt wahrscheinlich nicht. Müsste genaues Stringformat dazu kennen.
    FCommand.MenuName := FIniFile.ReadString('Command','Menuname',''); //So geht es wohl leider nicht, weil FCommand.Menuname -> ShortString!
    FCommand.DirName := FIniFile.ReadString('Command','Directory','');
    FCommand.ProgName := FIniFile.ReadString('Command','Exename',''); //Das funktioniert nicht so einfach, aber wie dann?
    FCommand.CfgFile := FIniFile.ReadString('Command','CfgFile','');
    FCommand.Options := FIniFile.ReadString('Command','Options','');

Wenn ich eine direkte Zuweisung ReadString an ShortString vornehme wird das hier nicht richtig ausgeführt:
Delphi-Quellcode:
if FCommand.MenuName = 'Mein Tool'
      then FCommand.OptionsDialog := TCommandOptOptDlg.Create(self)
Der Dialog wird nicht zugewiesen, also wird wohl der String fehlerhaft sein.
  Mit Zitat antworten Zitat