Page 1 of 1

Working with bitmaps...

PostPosted: November 26th, 2007, 5:17 pm
by dulef90
Hi everybody,
I'm trying to write a program which would be able to show bitmaps in a vertical line, one at the bottom of the other.
Does anyone know the way I could solve this problem?

I have this algorithm, but I have no idea how to modify it for this purpose:


Code: Select all
unit Unit1;

interface

uses
  Windows, SysUtils, Classes, Graphics, Forms;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormDestroy(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
    backgroundImage : TBitmap;
  end;

var
  Form1: TForm1;                           

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
backgroundImage := TBitmap.Create;
backgroundImage.LoadFromFile(ExtractFilePath(Application.ExeName)+'background.bmp');
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.Draw( 0, 0, backgroundImage );
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
backgroundImage.Free;
end;

end.



THANK YOU! :wink: :lol:

PostPosted: November 27th, 2007, 2:59 am
by Kambiz
What about using several TImage controls?

PostPosted: November 27th, 2007, 9:56 am
by dulef90
I'll try that. But I have one more question -
I have two forms - Form1 and Form2, and they are 'connected':
Code: Select all
unit Unit1 //Related to Form1;
var
  Form1: TForm1;

implementation

uses Unit2 //Related to Form2;

{$R *.dfm}

...

procedure TForm1.StrukturniprikazDNK1Click(Sender: TObject); // MainMenu Option
begin
  Form2.Show;
end;


The line of the bitmaps should appear in Form2, but this line of bitmaps is related to variable (s:array of string) from Form1. Is there any way Form2(Unit2) to 'see' global variables from Form1 (Unit1)? Or, how to define "SUPERGLOBAL' :shock: variable, which could be seen from any corelated Forms in one program :?:

PostPosted: November 27th, 2007, 2:17 pm
by Kambiz
You have the following ways:

1. Define a procedure in Form2 to get the string array as parameter.
2. Define another string array variable in Form2. Before showing Form2, copy form1 string array to it.
3. Use another unit to define string array inside it. Then use this unit in two form units.

PostPosted: November 28th, 2007, 6:58 pm
by dulef90
Kambiz wrote:You have the following ways:

1. Define a procedure in Form2 to get the string array as parameter.
2. Define another string array variable in Form2. Before showing Form2, copy form1 string array to it.
3. Use another unit to define string array inside it. Then use this unit in two form units.


I started using Delphi a month ago, so I'm still a beginner. I don't understand quite the theory you gave me here, so, could you write down a few codes so I can see how it works and what should I do? [-o<
Thank you! :lol:

PostPosted: November 29th, 2007, 3:41 am
by Kambiz
Code: Select all
Unit TheSahredUnit;

interface

var
  TheGlobalVariable: array[0..10] of Integer;

implementation

end.


Code: Select all
Unit Unit1;

interface

.
.
.

var
  Form1: TForm1;

implementation

uses
  Unit2, TheSharedUnit;

.
.
.

end.


Code: Select all
Unit Unit2;

interface

.
.
.

var
  Form2: TForm2;

implementation

uses
  TheSharedUnit;

.
.
.

end.

PostPosted: November 29th, 2007, 10:36 am
by dulef90
Thank you very much!!!

PostPosted: December 1st, 2007, 3:42 pm
by dulef90
It ALL worked, but, there's another problem:
There's some error at terminating the application.
Here is the code:

Code: Select all
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm2 = class(TForm)
    procedure FormActivate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    DNA: array of TBitmap;
  end;

var
  Form2: TForm2;
  l:integer;

implementation

uses
  Unit1;

{$R *.dfm}


procedure TForm2.FormActivate(Sender: TObject);
var i:integer;
begin
  If ADNA<>'' then begin
  l:=Length(ADNA);
  SetLength(DNA,l);
     If ADNA[1]='A' then
        begin
          DNA[1] := TBitmap.Create;
          DNA[1].LoadFromFile(ExtractFilePath(Application.ExeName)+'A5-T3.bmp');
        end;
      If ADNA[1]='G' then
        begin
          DNA[1] := TBitmap.Create;
          DNA[1].LoadFromFile(ExtractFilePath(Application.ExeName)+'G5-C3.bmp');
        end;
      If ADNA[1]='T' then
        begin
          DNA[1] := TBitmap.Create;
          DNA[1].LoadFromFile(ExtractFilePath(Application.ExeName)+'T5-A3.bmp');
        end;
      If ADNA[1]='C' then
        begin
          DNA[1] := TBitmap.Create;
          DNA[1].LoadFromFile(ExtractFilePath(Application.ExeName)+'C5-G3.bmp');
        end;
  For i:= 2 to l-1 do
    begin
      If ADNA[i]='A' then
        begin
          DNA[i] := TBitmap.Create;
          DNA[i].LoadFromFile(ExtractFilePath(Application.ExeName)+'A-T.bmp');
        end;
      If ADNA[i]='G' then
        begin
          DNA[i] := TBitmap.Create;
          DNA[i].LoadFromFile(ExtractFilePath(Application.ExeName)+'G-C.bmp');
        end;
      If ADNA[i]='T' then
        begin
          DNA[i] := TBitmap.Create;
          DNA[i].LoadFromFile(ExtractFilePath(Application.ExeName)+'T-A.bmp');
        end;
      If ADNA[i]='C' then
        begin
          DNA[i] := TBitmap.Create;
          DNA[i].LoadFromFile(ExtractFilePath(Application.ExeName)+'C-G.bmp');
        end;
    end;
      If ADNA[l]='A' then
        begin
          DNA[l] := TBitmap.Create;
          DNA[l].LoadFromFile(ExtractFilePath(Application.ExeName)+'A3-T5.bmp');
        end;
          If ADNA[l]='G' then
        begin
          DNA[l] := TBitmap.Create;
          DNA[l].LoadFromFile(ExtractFilePath(Application.ExeName)+'G3-C5.bmp');
        end;
      If ADNA[l]='T' then
        begin
          DNA[l] := TBitmap.Create;
          DNA[l].LoadFromFile(ExtractFilePath(Application.ExeName)+'T3-A5.bmp');
        end;
      If ADNA[l]='C' then
        begin
          DNA[l] := TBitmap.Create;
          DNA[l].LoadFromFile(ExtractFilePath(Application.ExeName)+'C3-G5.bmp');
        end;
    end;
end;

procedure TForm2.FormPaint(Sender: TObject);
var i:integer;
begin
  Form2.Height:= 385*l+10;
  For i:=1 to l do Canvas.Draw( 0, ((i-1)*385), DNA[i] );

end;

procedure TForm2.FormDestroy(Sender: TObject);
var i: integer;
begin
  For i:=1 to l do DNA[i].Free; // HERE IT REPORTS THE ERROR
end;

end.



Can you please tell what to do with that? [-o<
And, how to set vertical scroll bar to Form2? [-o<
Thank you!

PostPosted: December 1st, 2007, 4:09 pm
by Kambiz
Index of dynamic arrays starts from zero. For example, your last code should change to:

Code: Select all
procedure TForm2.FormDestroy(Sender: TObject);
var i: integer;
begin
  For i:=0 to l-1 do DNA[i].Free;
  DNA := nil;
end;


Remember to fix all other parts of your code.

PostPosted: December 1st, 2007, 4:11 pm
by dulef90
Kambiz wrote:Index of dynamic arrays starts from zero. For example, your last code should change to:

Code: Select all
procedure TForm2.FormDestroy(Sender: TObject);
var i: integer;
begin
  For i:=0 to l-1 do DNA[i].Free;
  DNA := nil;
end;


Remember to fix all other parts of your code.

Ok, I forgot that, i used to work in pascal.
Thank you! :wink:

PostPosted: December 1st, 2007, 4:30 pm
by dulef90
There's still a problem.
I've cut the image on screen with error report.
Do you know what it is?

[/img]

PostPosted: December 1st, 2007, 4:30 pm
by dulef90
The error is on the same place in the code.

PostPosted: December 1st, 2007, 5:04 pm
by Kambiz
Seems you didn't fix array indexes in other parts of your code.