SetTag example for Delphi
var
RasterIO: LEADRasterIO;
procedure TForm1.Button1Click(Sender: TObject);
begin
RasterIO:= CreateComObject(CLASS_LEADRasterIO) as LEADRasterIO;
end;
procedure TForm1.SetAndReadClick(Sender: TObject);
var
RasterVar: LEADRasterVariant;
begin
RasterVar:= coLEADRasterVariant.Create ( );
// initialize the array
RasterVar.ItemCount:= 4;
RasterVar.Type_:= VALUE_LONG;
RasterVar.LongItemValue[2]:= 2;
RasterVar.LongItemValue[3]:= 3;
RasterVar.LongItemValue[4]:= 127;
RasterIO.SetTag (32768, TAG_LONG, 0, RasterVar);
// RasterVar.Type_:= VALUE_STRING;
// RasterVar.StringValue:= 'My text string';
// RasterIO.SetTag (32768, TAG_ASCII, 0, RasterVar);
// Write the tag
RasterIO.WriteTag ('c:\ test.tif', 1);
ReadTag.Click ();
end;
procedure TForm1.ReadTagClick(Sender: TObject);
begin
// read the tag back
RasterIO.ReadTag ('c:\ test.tif', 1, 32768);
GetAndDisplayTag(0);
end;
//This sub will get a certain tag and display it according to the tag type.
Procedure TForm1.GetAndDisplayTag (lTag: Longint);
var
RasterVar: LEADRasterVariant;
Msg: String;
i: Longint;
count: Longint;
begin
RasterVar:= coLEADRasterVariant.Create ( );
RasterVar:= RasterIO.GetTagData (lTag);
count:= RasterIO.GetTagCount (lTag);
Msg:= 'Type = ' + IntToStr(RasterIO.GetTagType (lTag));
Msg:= Msg + Chr(10) + Chr(13) + 'count = ' + IntToStr(count);
if (RasterIO.GetTagType(lTag) = TAG_ASCII) then
Msg:= Msg + Chr(10) + Chr(13) + 'Data = ' + RasterVar.StringValue
else
begin
if ((RasterIO.GetTagType(lTag) = TAG_RATIONAL) Or
(RasterIO.GetTagType(lTag) = TAG_SRATIONAL)) then
begin
for i:= 1 to count do
begin
Msg:= Msg + Chr(10) + Chr(13) + 'Data(' + IntToStr(i) + ') = ' +
IntToStr(RasterVar.ShortItemValue[i * 2]) + '/' + IntToStr(RasterVar.ShortItemValue[i * 2 + 1]);
end;
end
else
for i:= 0 to count - 1 do
begin
Msg:= Msg + Chr(10) + Chr(13) + 'Data(' + IntToStr(i) + ') = ' +
IntToStr(RasterVar.ShortItemValue[i]);
end;
end;
ShowMessage (Msg);
end;