⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elec_2.~pas

📁 自己编写有关电路计算方面的DELPHI 程序
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
     StringGrid3.Cells[j,row_select+1]:=floattostr(Y[j,row_select+1]);
     StringGrid3.Cells[row_select+1,j]:=floattostr(Y[row_select+1,j]);
     StringGrid3.Cells[k,row_select+1]:=floattostr(Y[k,row_select+1]);
     StringGrid3.Cells[row_select+1,k]:=floattostr(Y[row_select+1,k]);
                                                             {常数矩阵显示}
     StringGrid5.Cells[1,SpinEdit1.Value]:=floattostr(B[SpinEdit1.Value]);
     end
     else
       showmessage('数组下标越界,重新输入节点标号');
end;


{电流控制电流源}
procedure TForm1.N51Click(Sender: TObject);
var
   u,v,w,z,h:integer;
begin
   StringGrid2.Cells[6,row_select]:= N51.Caption;
   if TryStrToInt(trim(StringGrid2.Cells[1,row_select]),u) then                                                     {取下标}
        j:=u
     else
        showmessage('节点J标号置入错误,重新输入节点J标号');
     if TryStrToInt(trim(StringGrid2.Cells[2,row_select]),v) then
        k:=v
     else
        showmessage('节点K标号置入错误,重新输入节点K标号');
     if TryStrToInt(trim(StringGrid2.Cells[3,row_select]),w) then                                                     {取下标}
        f:=w
     else
        showmessage('节点F标号置入错误,重新输入节点F标号');
     if TryStrToInt(trim(StringGrid2.Cells[4,row_select]),z) then
        t:=z
     else
        showmessage('节点T标号置入错误,重新输入节点T标号');
     if TryStrToInt(trim(StringGrid2.Cells[5,row_select]),z) then
        m:=h
     else
        showmessage('数据M置入错误,重新输入数据M');

     if (k < SpinEdit1.Value+4) and (j  < SpinEdit1.Value+4) then
       begin
         Y[j,f]:=Y[j,f]+(D[row_select-1]*D[m-1]);
         Y[j,t]:=Y[j,t]-(D[row_select-1]*D[m-1]);
         Y[k,f]:=Y[k,f]-(D[row_select-1]*D[m-1]);
         Y[k,t]:=Y[k,t]+(D[row_select-1]*D[m-1]);

         StringGrid3.Cells[j,f]:=floattostr(Y[j,f]);
         StringGrid3.Cells[j,t]:=floattostr(Y[j,t]);
         StringGrid3.Cells[k,f]:=floattostr(Y[k,f]);
         StringGrid3.Cells[k,t]:=floattostr(Y[k,t]);

       end
     else
       showmessage('数组下标越界,重新输入节点标号');

end;


{电压控制电流源}
procedure TForm1.N4Click(Sender: TObject);
var
   u,v,w,z:integer;

begin

     StringGrid2.Cells[6,row_select]:= N4.Caption ;
     if TryStrToInt(trim(StringGrid2.Cells[1,row_select]),u) then                                                     {取下标}
        j:=u
     else
        showmessage('节点J标号置入错误,重新输入节点J标号');
     if TryStrToInt(trim(StringGrid2.Cells[2,row_select]),v) then
        k:=v
     else
        showmessage('节点K标号置入错误,重新输入节点K标号');
     if TryStrToInt(trim(StringGrid2.Cells[3,row_select]),w) then                                                     {取下标}
        f:=w
     else
        showmessage('节点F标号置入错误,重新输入节点F标号');
     if TryStrToInt(trim(StringGrid2.Cells[4,row_select]),z) then
        t:=z
     else
        showmessage('节点T标号置入错误,重新输入节点T标号');

     if (k < SpinEdit1.Value+4) and (j  < SpinEdit1.Value+4) then
     begin
     Y[j,f]:=Y[j,f]+D[row_select-1];
     Y[j,t]:=Y[j,t]-D[row_select-1];
     Y[k,f]:=Y[k,f]-D[row_select-1];
     Y[k,t]:=Y[k,t]+D[row_select-1];

     StringGrid3.Cells[j,f]:=floattostr(Y[j,f]);
     StringGrid3.Cells[j,t]:=floattostr(Y[j,t]);
     StringGrid3.Cells[k,f]:=floattostr(Y[k,f]);
     StringGrid3.Cells[k,t]:=floattostr(Y[k,t]);
     end
     else
       showmessage('数组下标越界,重新输入节点标号');

end;

{电压源中电流控制电流源}
procedure TForm1.N61Click(Sender: TObject);
var
   u,v:integer;

begin
     StringGrid2.Cells[6,row_select]:= N61.Caption;
     if TryStrToInt(trim(StringGrid2.Cells[1,row_select]),u) then                                                     {取下标}
        j:=u
     else
        showmessage('节点J标号置入错误,重新输入节点J标号');
     if TryStrToInt(trim(StringGrid2.Cells[2,row_select]),v) then
        k:=v
     else
        showmessage('节点K标号置入错误,重新输入节点K标号');
     if (k < SpinEdit1.Value+4) and (j  < SpinEdit1.Value+4) then
     begin
       Y[j,row_select+1]:=Y[j,row_select+1]+D[row_select-1];
       Y[k,row_select+1]:=Y[k,row_select+1]-D[row_select-1];

       StringGrid3.Cells[j,row_select+1]:=floattostr(Y[j,row_select+1]);
       StringGrid3.Cells[k,row_select+1]:=floattostr(Y[k,row_select+1]);
     end
     else
       showmessage('数组下标越界,重新输入节点标号');

end;

{电压源控制电压源}
procedure TForm1.N71Click(Sender: TObject);

var
   u,v,w,z:integer;
begin
      StringGrid2.Cells[6,row_select]:= N71.Caption;
      if TryStrToInt(trim(StringGrid2.Cells[1,row_select]),u) then                                                     {取下标}
        j:=u
     else
        showmessage('节点J标号置入错误,重新输入节点J标号');
     if TryStrToInt(trim(StringGrid2.Cells[2,row_select]),v) then
        k:=v
     else
        showmessage('节点K标号置入错误,重新输入节点K标号');
     if TryStrToInt(trim(StringGrid2.Cells[3,row_select]),w) then                                                     {取下标}
        f:=w
     else
        showmessage('节点F标号置入错误,重新输入节点F标号');
     if TryStrToInt(trim(StringGrid2.Cells[4,row_select]),z) then
        t:=z
     else
        showmessage('节点T标号置入错误,重新输入节点T标号');

     if (k < SpinEdit1.Value+4) and (j  < SpinEdit1.Value+4)then
     begin                                             {对系数矩阵赋值}
        Y[j,row_select+2]:=1;
        Y[k,row_select+2]:=-1;
        Y[row_select+2,j]:=1;
        Y[row_select+2,k]:=-1;
        Y[row_select+2,f]:=Y[row_select+2,f]-D[row_select-1];
        Y[row_select+2,t]:=Y[row_select+2,t]+D[row_select-1];

        StringGrid3.Cells[j,row_select+2]:=floattostr(Y[j,row_select+2]);
        StringGrid3.Cells[k,row_select+2]:=floattostr(Y[k,row_select+2]);
        StringGrid3.Cells[row_select+2,j]:=floattostr(Y[row_select+2,j]);
        StringGrid3.Cells[row_select+2,k]:=floattostr(Y[row_select+2,k]);
        StringGrid3.Cells[row_select+2,f]:=floattostr(Y[row_select+2,f]);
        StringGrid3.Cells[row_select+2,t]:=floattostr(Y[row_select+2,t]);

      end
      else
       showmessage('数组下标越界,重新输入节点标号');

end;

{电流源控制电压源}
procedure TForm1.N81Click(Sender: TObject);
var
   u,v,w,z,h:integer;

begin
     StringGrid2.Cells[6,row_select]:= N81.Caption ;
     if TryStrToInt(trim(StringGrid2.Cells[1,row_select]),u) then                                                     {取下标}
        j:=u
     else
        showmessage('节点J标号置入错误,重新输入节点J标号');
     if TryStrToInt(trim(StringGrid2.Cells[2,row_select]),v) then
        k:=v
     else
        showmessage('节点K标号置入错误,重新输入节点K标号');
     if TryStrToInt(trim(StringGrid2.Cells[3,row_select]),w) then                                                     {取下标}
        f:=w
     else
        showmessage('节点F标号置入错误,重新输入节点F标号');
     if TryStrToInt(trim(StringGrid2.Cells[4,row_select]),z) then
        t:=z
     else
        showmessage('节点T标号置入错误,重新输入节点T标号');
     if TryStrToInt(trim(StringGrid2.Cells[5,row_select]),z) then
        m:=h
     else
        showmessage('数据M置入错误,重新输入数据M');
      if (k < SpinEdit1.Value+4) and (j  < SpinEdit1.Value+4)then
      begin
        Y[j,row_select+3]:=1;
        Y[k,row_select+3]:=-1;
        Y[row_select+3,j]:=1;
        Y[row_select+3,k]:=-1;
        Y[row_select+3,f]:=Y[row_select+3,f]-(D[row_select-1]*D[m-1]);
        Y[row_select+3,t]:=Y[row_select+3,t]+(D[row_select-1]*D[m-1]);

        StringGrid3.Cells[j,row_select+3]:=floattostr(Y[j,row_select+3]);
        StringGrid3.Cells[k,row_select+3]:=floattostr(Y[k,row_select+3]);
        StringGrid3.Cells[row_select+3,j]:=floattostr(Y[row_select+3,j]);
        StringGrid3.Cells[row_select+3,k]:=floattostr(Y[row_select+3,k]);
        StringGrid3.Cells[row_select+3,f]:=floattostr(Y[row_select+3,f]);
        StringGrid3.Cells[row_select+3,t]:=floattostr(Y[row_select+3,t]);
      end
      else
       showmessage('数组下标越界,重新输入节点标号');

end;

{电压源中电流源控制电压源}
procedure TForm1.N91Click(Sender: TObject);
var
   u,v:integer;

begin
      StringGrid2.Cells[6,row_select]:= N91.Caption ;
      if TryStrToInt(trim(StringGrid2.Cells[1,row_select]),u) then                                                     {取下标}
        j:=u
     else
        showmessage('节点J标号置入错误,重新输入节点J标号');
     if TryStrToInt(trim(StringGrid2.Cells[2,row_select]),v) then
        k:=v
     else
        showmessage('节点K标号置入错误,重新输入节点K标号');
     if (k < SpinEdit1.Value+4) and (j  < SpinEdit1.Value+4) then
     begin
        Y[j,row_select+4]:=1;
        Y[k,row_select+4]:=-1;
        Y[row_select+4,j]:=1;
        Y[row_select+4,k]:=-1;
        Y[row_select+4,row_select+1]:=Y[row_select+4,row_select+1]-D[row_select-1];

        StringGrid3.Cells[j,row_select+4]:=floattostr(Y[j,row_select+4]);
        StringGrid3.Cells[k,row_select+4]:=floattostr(Y[k,row_select+4]);
        StringGrid3.Cells[row_select+4,j]:=floattostr(Y[row_select+4,j]);
        StringGrid3.Cells[row_select+4,k]:=floattostr(Y[row_select+4,k]);
        StringGrid3.Cells[row_select+4,row_select+1]:=floattostr(Y[row_select+4,row_select+1]);
     end
     else
       showmessage('数组下标越界,重新输入节点标号');
end;

procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
var
  v:double;
begin
      if  tryStrToFloat(value,v) then
         D[ACol]:= v
      else
        begin
           StringGrid1.Cells[ACol,ARow]:=value;
           if  StringGrid1.Cells[ACol,ARow]<>'' then
              showmessage('录入数据非法');
           D[ACol]:= 0;
        end;

end;

procedure TForm1.StringGrid2SetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
VAR
  V:integer;
begin
      if  not TryStrToInt(value,v) then
      begin
      StringGrid2.Cells[ACol,ARow]:=value;
      if  StringGrid2.Cells[ACol,ARow]<>'' then
      showmessage('录入数据非法');

      end;
end;

procedure TForm1.StringGrid5SetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
var
 v:double;
begin
      if  not tryStrToFloat(value,v) then
      begin
      StringGrid5.Cells[ACol,ARow]:=value;
      if  StringGrid5.Cells[ACol,ARow]<>'' then
      showmessage('录入数据非法');
      
      end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
      showmessage(floattostr(D[1]));
     { showmessage(floattostr(Y[1,1])); }
end;



procedure TForm1.Button4Click(Sender: TObject);
var
  aa:integer;
begin

    SpinEdit1.Value:=0;
      {清空赋值表格}
   with StringGrid1 do
       for aa := 0 to ColCount - 1 do
           Cols[aa].Clear;
   stringgrid1.ColCount:= 1;
   stringgrid1.RowCount:= 1;



   {清空数据置入表格}
   with StringGrid2 do
       for aa := 0 to ColCount - 1 do
           Cols[aa].Clear;
   stringgrid2.RowCount:= 1;
   stringgrid2.ColCount:= 1;



   {清空矩阵表格}
   with StringGrid3 do
       for aa := 0 to ColCount - 1 do
           Cols[aa].Clear;
   stringgrid3.ColCount:= 1;
   stringgrid3.RowCount:= 1;


   {清空结果数据表格}
   with StringGrid4 do
       for aa := 0 to ColCount - 1 do
           Cols[aa].Clear;
   stringgrid4.ColCount:= 1;
   stringgrid4.RowCount:= 1;



   {清空数据置入表格}
   with StringGrid5 do
       for aa := 0 to ColCount - 1 do
           Cols[aa].Clear;
   stringgrid5.ColCount:= 1;
   stringgrid5.RowCount:= 1;

    {清空各数组}
     Y:=nil;
     B:=nil;
     X:=nil;
     D:=nil;


end;



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -