unit class_rd_image;

interface

uses Classes, Windows, AdvPicture;

{$REGION 'КЛАСС "ИЗОБРАЖЕНИЕ"'}
type
  TRDPointImage = class (TObject)
    private
      dll_name: PWideChar;
      resource_name: string;
      internal_image: TIPicture; 

      function GetResourceAsJpeg( const resname: string; AInstance: Cardinal): TIPicture;
    public
      function get_image(): TIPicture;
      function Destroy_internal_image:boolean;
      
      constructor Create ( in_dll_name: PWideChar; in_resource_name:string); virtual;
      destructor  Destroy; override;
end;
{$ENDREGION}

implementation

constructor TRDPointImage.Create(in_dll_name:  PWideChar; in_resource_name: string);
begin
  inherited Create;
  if ( in_dll_name <> '' ) then
  begin
    if ( in_resource_name <> '' ) then
      begin
         self.dll_name := in_dll_name;
         self.resource_name := in_resource_name;
      end
      else
      begin
        //обработка ошибки пустого имени ресурса точки
      end;
  end
  else
  begin
    //обработка ошибки пустого имени ресурса точки
  end;
end;

destructor TRDPointImage.Destroy;
begin
  self.dll_name := '';
  self.resource_name := '';
end;

function TRDPointImage.get_image(): TIPicture;
var
  h: THandle;
begin
  result := nil;
  h := LoadLibrary( self.dll_name );
  if h>0 then
    begin
      try                       
         self.internal_image := GetResourceAsJpeg( self.resource_name, h);
      finally
         result := self.internal_image;
      end;
    end
    else 
    begin
      result := nil;
      //обработка ошибки
    end;
end;

function TRDPointImage.Destroy_internal_image: boolean;
begin
  try
    self.internal_image.Destroy;
  finally
    result := true;
  end;
end;

function TRDPointImage.GetResourceAsJpeg( const resname: string; AInstance: Cardinal ): TIPicture;
var
  Stream: TResourceStream;
begin
result := TIPicture.Create; 
  try
      Stream := TResourceStream.Create( AInstance, ResName, 'JPEG' );
      try
        result.LoadFromStream( Stream );
      finally
          Stream.Free;
      end;
      exit;
  except
      on ex: EResNotFound do
      begin
          //здесь обработка исключения если ресурс не найден
      end;
  end;
end;

end.
