Назначьте объявленное Const Name для переменной в Delphi
Есть ли способ назначить объявленное имя const для var? У меня есть код ниже, где есть некоторые Cons, объявленные как строки, эти строки являются изображениями в формате JSON, но в зависимости от выбранного значения я хочу отобразить изображение или другое;
unit Images;
interface
Const
Image1 = '[84,80,70,48,22,84,87,114,97,112,112,101,114,77,117,108,116,105,82,101, 48, 34]';
Image2 = '[84,80,70,48,22,84,87,114,97,112,112,101,114,77,117,108,116,105,82,101, 90, 47]';
Image3 = '[84,80,70,48,22,84,87,114,97,112,112,101,114,77,117,108,116,105,82,101, 22, 74]';
.
.
.
.
.
.
.
implementation
end.
unit MainForm;
interface
uses
Images...
type
TForm1 = class(TForm)
Picture1: TImage;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure ListBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure AsignJSONToImage(ImageString: String; DisplayImage: TImage);
end;
var
Form1: TForm1;
implementation
procedure TForm1.AsignJSONToImage(ImageString: String; DisplayImage: TImage);
var
Stream: TStream;
JsonArray: TJSONArray;
begin
jsonArray := TJSONObject.ParseJSONValue(ImageString) as TJSONArray;
try
Stream := TMemoryStream.Create;
Stream := TDBXJSONTools.JSONToStream(jsonArray);
try
Stream.Position := 0;
DisplayImage.MultiResBitmap.LoadFromStream(Stream);
finally
Stream.Free;
end;
finally
jsonArray.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items.Add('Image1');
ListBox1.Items.Add('Image2');
ListBox1.Items.Add('Image3');
end;
procedure TForm1.ListBox1Change(Sender: TObject);
var
Item: TListBoxItem;
begin
Item := Listbox1.Selected;
AsignJSONToImage(Item.Text, Picture1); {* Here in the first parameter,I want to pass the name of the const selected in Listbox1 but not the text itself to display the image in Picture1*}
end;
end.
Я надеюсь, вы понимаете, что я хочу сделать, большое спасибо за вашу благодарную помощь.
С уважением.