Показать сообщение отдельно
  #21  
Старый 12.11.2012, 14:47
Pavel_Aleksandrovich Pavel_Aleksandrovich вне форума
Прохожий
 
Регистрация: 02.09.2012
Сообщения: 31
Репутация: 9
По умолчанию

Доброе время суток

Исправил ошибки предыдущего кода все работает
Код:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

tuchastok=class
          private
                 fdlina:real;
                 fploshad:real;
          public
                property dlina:real
                        read fdlina
                        write fdlina;
                property ploshad:real
                        read fploshad
                        write fploshad;
end;

var
  Form1: TForm1;
  uchastok:array of tuchastok;
  
implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
var
   i, j:integer;
   x:array of integer;
   y:array of integer;
   y_os:integer;

begin
     setlength(x, 7);
     setlength(y, 7);

     x[0]:=100;
     y[0]:=100;

     for i:=0 to 2 do
        begin
             uchastok[i].dlina:=3*i+2;
             uchastok[i].ploshad:=2*i+2;
        end;

     y_os:=y[0]+round((uchastok[0].ploshad*10)/2);

     i:=0;
     for j:=1 to 5 do
        begin
             if (j mod 2)>0
               then
                   begin
                        x[j]:=round(uchastok[i].dlina*100);
                        x[j+1]:=round(uchastok[i].dlina*100);
                        i:=i+1;
                   end;
        end;

     i:=0;
     for j:=1 to 5 do
        begin
             if j=1
               then
                   begin
                        y[j]:=y_os+round((uchastok[i].ploshad*10)/2);
                        i:=i+1;
                   end
               else
                   begin
                        if (j mod 2)=0
                          then
                              begin
                                   y[j]:=y_os-round((uchastok[i].ploshad*10)/2);
                                   y[j+1]:=y_os+round((uchastok[i].ploshad*10)/2);
                                   i:=i+1;
                              end;
                   end;
        end;

     for i:=0 to 4 do
        begin
             form1.Canvas.Rectangle(x[i], y[i], x[i+1], y[i+1]);
        end;

end;

procedure TForm1.FormCreate(Sender: TObject);
var
   i:integer;
begin
     setlength(uchastok, 3);
     for i:=0 to 2 do
        begin
             uchastok[i]:=tuchastok.Create;
        end;
end;

end.


теперь данный алгоритм надо вынести в отдельный модуль
написал, вот что получилось

1 модуль
Код:
unit tuchastok;

interface

uses Controls, StdCtrls, SysUtils, Dialogs;

type
    tuchastok=class
         private
                fdlina:real;
                fploshad:real;
         public
                property dlina:real
                        read fdlina
                        write fdlina;
                property ploshad:real
                        read fploshad
                        write fplshad;
    end;

implementation

end.


2 модуль
Код:
unit balka;

interface

uses Controls, StdCtrls, SysUtils, Dialogs;

type
    tbalka=class
         private
                fuchastok:array of tuchastok;
                fshema:tcanvas;
                procedure setshema(value:tcanvas);
         public
               property uchastok:array of tuchastok
                       read fuchastok
                       write fuchastok;
               property shema:tcanvas
                       write setshema;
    end;

implementation

uses tuchastok;

procedure tbalka.setshema(value:tcanvas);
         var
            x:array of integer;
            y:array of integer;
            y_os:integer;
            i, j:integer;

         begin
              setlength(uchastok, 3);
              setlength(x, 7);
              setlength(y, 7);

              x[0]:=100;
              y[0]:=100;

              y_os:=y[0]+round((uchastok[0].ploshad*10)/2);

              i:=0;
              for j:=1 to 5 do
                 begin
                      if (j mod 2)>0
                        then
                            begin
                                 x[j]:=round(uchastok[i].dlina*100);
                                 x[j+1]:=round(uchastok[i].dlina*100);
                                 i:=i+1;
                            end;
                 end;

              i:=0;
              for j:=1 to 5 do
                 begin
                      if j=1
                        then
                            begin
                                 y[j]:=y_os+round((uchastok[i].ploshad*10)/2);
                                 i:=i+1;
                            end
                        else
                            begin
                                 if (j mod 2)=0
                                   then
                                       begin
                                            y[j]:=y_os-round((uchastok[i].ploshad*10)/2);
                                            y[j+1]:=y_os+round((uchastok[i].ploshad*10)/2);
                                            i:=i+1;
                                       end;
                            end;
                 end;

              for i:=0 to 4 do
                 begin
                      value.Rectangle(x[i], y[i], x[i+1], y[i+1]);
                 end;
              shema:=value;

end.

3 модуль
Код:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses balka, tuchastok;

{$R *.dfm}
var
   balka:tbalka;

procedure TForm1.FormCreate(Sender: TObject);
begin
     balka:=tbalka.create;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     with balka do
         begin
              uchastok[0].dlina:=0.6;
              uchastok[0].ploshad:=2*30;
              uchastok[1].dlina:=0.4;
              uchastok[1].ploshad:=30;
              uchastok[2].dlina:=0.5;
              uchastok[2].ploshad:=30;
         end;

     balka.setshema(form1.canvas);

end;

end.

естественно не компилирует жду от вас помощи
Ответить с цитированием