TVirtualDrawtree

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

can i use images in picture container ? , or in imagelist1 i dont want to put resource files on client machine
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

resource file is not separated file, embedded to the project EXE file.
So there is only one executable file contains icons, images, documents, ext.. many files inside as packed.

if there is only one image you want to use, put a timage more on the form and use this.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

i will use this in activex not in exe mrmarman , and also i will use default icons not only one i will store them in Timagelist can i do that ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

Then why the code below works... :wink:

( ActiveX is also a EXE file )

Kod: Tümünü seç

{$R RES\ARMAN.RES}


Var
  xDefaultBMP : TBitmap;

procedure TForm1.FormCreate(Sender: TObject);
Var
  ResStream : TResourceStream;
begin
  xDefaultBMP := TBitmap.Create;
  ResStream  := TResourceStream.Create(HInstance, 'DefBitmap', RT_RCDATA);
    xDefaultBMP.LoadFromStream( ResStream );
  ResStream.Free;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Image1.Picture.Bitmap.Assign( xDefaultBMP );
end;

Dosya ekleri
ActiveX_ResourceStream.rar
ActiveX - Resstream Code Project
(253.64 KiB) 64 kere indirildi
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

if i have to store images into resource file i don't need to store it on client pc ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

Because, allready all images transfered inside / embedded by OCX file.
This is in the case of static images like default.bmp, special html, MSExcel or MSWord files even any static database (database must be readonly) for use reporting or other purposes.

You may add more statements to RC file is anought for storing them into OCX file. But you not to forget execute BRCC32.exe before build project. ( I put a batch file for this ) The batch file you run, that will build a RES file from RC file text list.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

i got access violation here what i do

Kod: Tümünü seç

Procedure TForm1.Add_Item( strCaption: String; ListView : TListView; strFile: String; boolBlink : Boolean );
Var
  MS : TMemoryStream;
begin
if Strfile = '' then
  aGIF := aGIF.Create;
  ResStream  := TResourceStream.Create(HInstance, 'f1', RT_RCDATA);
  aGIF.LoadFromStream( ResStream );
    ResStream.Free;

begin
  MS := TMemoryStream.Create;
  DownloadToStream(strFile, ms);// start downloading file to stream
  ms.Position := 0;
  if ExtractFileExt(strFile) = '.gif' then  // if image is gif
begin
  aGIF := TGifImage.Create;
  aGIF.LoadFromStream(MS);
  aGIF.Transparent := True;
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( aGif ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add('123456');
  end;
end;
Rc data content

f1 RCDATA f1.gif
f2 RCDATA f2.gif

Kod: Tümünü seç

implementation

{$R *.dfm}
{$R resource\defaultimg.RES}
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

You forgot begin / end block I see...

Kod: Tümünü seç

if Strfile = '' then 
begin
  aGIF := aGIF.Create;
  ResStream  := TResourceStream.Create(HInstance, 'f1', RT_RCDATA);
  aGIF.LoadFromStream( ResStream );
    ResStream.Free;
end else begin
// ... //
end;
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

still getting assess violation

Kod: Tümünü seç

Procedure TForm1.Add_Item( strCaption: String; ListView : TListView; strFile: String; boolBlink : Boolean );
Var
  MS : TMemoryStream;
  ResStream : TResourceStream;

begin
  if Strfile = '' then
begin
  aGIF := aGIF.Create;
  ResStream  := TResourceStream.Create(HInstance, 'f1', RT_RCDATA);
  aGIF.LoadFromStream( ResStream );
    ResStream.Free;
end else

begin
  MS := TMemoryStream.Create;
  DownloadToStream(strFile, ms);// start downloading file to stream
  ms.Position := 0;
  if ExtractFileExt(strFile) = '.gif' then  // if image is gif
begin
  aGIF := TGifImage.Create;
  aGIF.LoadFromStream(MS);
  aGIF.Transparent := True;
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( aGif ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add('123456');
  end;
end;


if ExtractFileExt(strFile) = '.jpg' then // if image jpg
begin
  jpg := TJPEGImage.Create;
  jpg.LoadFromStream(MS);
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( jpg ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add('123456');
  end;
end;

if ExtractFileExt(strFile) = '.png' then //if image png
begin
  png := TPngImage.Create;
  png.LoadFromStream(MS);
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( png ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add('123456');
  end;
end;
end;

  // DO NOT Free this image because now it is a SubItems[1] Object
  FreeAndNil(MS);
end;

Rc data content

f1 RCDATA f1.gif
f2 RCDATA f2.gif

Code: Select all

Kod: Tümünü seç

implementation

{$R *.dfm}
{$R resource\defaultimg.RES}
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

What is aGIF ? Why it is not TGIFImage ?
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

agif is global variable aGIF : TGifImage; its TGIFImage
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

oh omg iam stupid iam really stupid it works thank you may bad thank youuuuuuuuuuuuuuu
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

here is the final result i dont know if this the right way to do the checks its working but i dont know i do it right or wrong

Kod: Tümünü seç

Procedure TForm1.Add_Item( strCaption: String; ListView : TListView; strFile: String; boolBlink : Boolean );
Var
  MS : TMemoryStream;
  ResStream : TResourceStream;

begin
  if Strfile = '' then
begin
  aGIF := TGifImage.Create;
  ResStream  := TResourceStream.Create(HInstance, 'f1', RT_RCDATA);
  aGIF.LoadFromStream( ResStream );
    ResStream.Free;
      With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( aGif ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add('123456');
  end;
end else

begin
  MS := TMemoryStream.Create;
  DownloadToStream(strFile, ms);// start downloading file to stream
  ms.Position := 0;
  if ExtractFileExt(strFile) = '.gif' then  // if image is gif
begin
  aGIF := TGifImage.Create;
  aGIF.LoadFromStream(MS);
  aGIF.Transparent := True;
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( aGif ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add('123456');
  end;
end;


if ExtractFileExt(strFile) = '.jpg' then // if image jpg
begin
  jpg := TJPEGImage.Create;
  jpg.LoadFromStream(MS);
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( jpg ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add('123456');
  end;
end;

if ExtractFileExt(strFile) = '.png' then //if image png
begin
  png := TPngImage.Create;
  png.LoadFromStream(MS);
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    SubItems.AddObject( 'IMA', TObject( png ) ); // subitem 1
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
      SubItems.Add('123456');
  end;
end;

  // DO NOT Free this image because now it is a SubItems[1] Object
  FreeAndNil(MS);
end;
end;
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: TVirtualDrawtree

Mesaj gönderen mrmarman »

I've optimized the code for maximum yield with small code... :roll:

P.S: You need to remove remark for PNG file format. I remarked the png, because I have not PNG unit right now.

Kod: Tümünü seç

{$R *.dfm}
{$R resource\defaultimg.RES}

Uses GIFImg, JPEG, IdHttp, GraphUtil;

Var
  xboolBlink : Boolean = False;

Procedure TForm1.Add_Item( strCaption: String; ListView : TListView; strFile: String; boolBlink : Boolean );
  procedure DownloadToStream(strUrl:String; MS:TMemoryStream);
  begin
    With TIdHttp.Create(nil) do begin
      Get(strUrl, MS);
      Ms.Seek(0, soFromBeginning);
      Free;
    end;
  end;
Var
  MS        : TMemoryStream;
  ResStream : TResourceStream;
  iType     : Integer;
  aGIF : TGIFImage;
  aJPG : TJPEGImage;
//aPNG : TPNGImage;
begin
  iType := -1;
  if Strfile = '' then iType := 0;
  if ExtractFileExt(strFile) = '.gif' then iType := 1;
  if ExtractFileExt(strFile) = '.jpg' then iType := 2;
//if ExtractFileExt(strFile) = '.png' then iType := 3;
  With ListView.Items.Add do
  begin
    Caption   := '';
    SubItems.Add( strCaption ); // subitem 0
    case iType of
    0: begin
         ResStream  := TResourceStream.Create(HInstance, 'f1', RT_RCDATA);
           aGIF := TGIFImage.Create;
           aGIF.LoadFromStream( ResStream );
           SubItems.AddObject( 'IMA', TObject( aGif ) ); // subitem 1
         ResStream.Free;
       end;
    1: begin
         MS := TMemoryStream.Create;
         DownloadToStream(strFile, ms);// start downloading file to stream
         MS.Position := 0;
           aGIF := TGifImage.Create;
           aGIF.LoadFromStream(MS);
           aGIF.Transparent := True;
           SubItems.AddObject( 'IMA', TObject( aGif ) ); // subitem 1
         FreeAndNil(MS);
       end;
    2: begin
         MS := TMemoryStream.Create;
         DownloadToStream(strFile, ms);// start downloading file to stream
         MS.Position := 0;
           aJPG := TJPEGImage.Create;
           aJPG.LoadFromStream(MS);
           SubItems.AddObject( 'IMA', TObject( aJPG ) ); // subitem 1
         FreeAndNil(MS);
       end;
  //3: begin
  //     MS := TMemoryStream.Create;
  //     DownloadToStream(strFile, ms);// start downloading file to stream
  //     MS.Position := 0;
  //       aPNG := TPngImage.Create;
  //       aPNG.LoadFromStream(MS);
  //       SubItems.AddObject( 'IMA', TObject( aPNG ) ); // subitem 1
  //     FreeAndNil(MS);
  //   end;
    end;
    if boolBlink
      then  SubItems.Add( 'blink' ) // subitem 2
      else  SubItems.Add( '' );     // subitem 2
    SubItems.Add('123456');
  end; // With ListView
  // DO NOT Free this image because now it is a SubItems[1] Object
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  Add_Item( 'ARMAN', ListView1, 'http://laughingsquid.com/wp-content/uploads/tumblr_mekph2vuHq1rllcopo1_500.gif', False );
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
  Add_Item( 'ARMAN', ListView1, '', False );
end;
Resim
Dosya ekleri
ActiveX_ResourceStream_NEW.rar
Optimized code
(38.74 KiB) 67 kere indirildi
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: TVirtualDrawtree

Mesaj gönderen mia »

yoU are a Genius i love you mrmarman enough for today i will get back with question tomorrow
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Cevapla