文档库 最新最全的文档下载
当前位置:文档库 › 电阻的色环代码

电阻的色环代码

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Panel1: TPanel;
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Shape6: TShape;
Shape7: TShape;
Shape8: TShape;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Panel2: TPanel;
Panel3: TPanel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
ColorBox1: TColorBox;
ColorBox2: TColorBox;
ColorBox3: TColorBox;
ColorBox4: TColorBox;
ColorBox5: TColorBox;
ColorBox6: TColorBox;
ColorBox7: TColorBox;
ColorBox8: TColorBox;
Label11: TLabel;
ColorBox9: TColorBox;
Label12: TLabel;
Label13: TLabel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure ColorBox1Change(Sender: TObject);
procedure ColorBox2Change(Sender: TObject);
procedure ColorBox3Change(Sender: TObject);
procedure ColorBox4Change(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure ColorBox5Change(Sender: TObject);
procedure ColorBox6Change(Sender: TObject);
procedure ColorBox7Change(Sender: TObject);
procedure ColorBox8Change(Sender: TObject);
procedure ColorBox9Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

type
array1=array[1..5]of integer;
function js1(f1:array1):real;
function js2(f1:array1):real;
var
Form1: TForm1;
zf1: array1;
ou,cs,jd,bj,sw,uw,jg: real;

implementation

{$R *.dfm}

function js1(f1:array1):real;
var
i:integer;
begin
ou:=0;
bj:=0;
for i:=1 to 5 do
begin
if i=1 then
begin
cs:=10;
end;
if i=2 then
begin
cs:=1;
end;
case f1[i] of

clMaroon: if i<3 then begin ou:=ou+cs*1; end
else if i=3 then begin ou:=ou*10.0; end
else begin jd:=20; bj:=1; end;
clRed : if i<3 then begin ou:=ou+cs*2; end
else begin ou:=ou*10.0*10.0; end;
clLime : if i<3 then begin ou:=ou+cs*3; end
else begin ou:=ou*10*10*10; end;
clYellow: if i<3 then begin ou:=ou+cs*4; end
else begin ou:=ou*10*10*10*10; end;
clGreen : if i<3 then begin ou:=ou+cs*5; end
else begin ou:=ou*10*10*10*10*10; end;
clBlue : if i<3 then begin ou:=ou+cs*6; end
else begin ou:=ou*10*10*10*10*10*10; end;
clPurple: if i<3 then begin ou:=ou+cs*7; end
else begin ou:=ou*10*10*10*10*10*10*10; end;
clGray: if i<3 then begin ou:=ou+c

s*8; end
else begin ou:=ou*10*10*10*10*10*10*10*10; end;
clwhite: if i<3 then begin ou:=ou+cs*9; end
else begin ou:=ou*10*10*10*10*10*10*10*10*10; end;
clBlack: if i<>3 then begin ou:=ou; end
else begin bj:=0; end;
clSilver: begin jd:=10; bj:=1; end;

clOlive: begin jd:=5; bj:=1; end;
end;
end;
js1:=ou;
end;
function js2(f1:array1):real;
var
i:integer;
begin //1
ou:=0;
bj:=0;
for i:=1 to 6 do
begin //2
if i=1 then
begin
cs:=100;
end;
if i=2 then
begin
cs:=10;
end;
if i=3 then
cs:=1;
case f1[i] of
clMaroon: if i<4 then begin ou:=ou+cs*1; end
else if i=4 then begin ou:=ou*10.0; end
else begin jd:=20; bj:=1; end;
clRed : if i<4 then begin ou:=ou+cs*2; end
else begin ou:=ou*10.0*10.0; end;
clLime : if i<4 then begin ou:=ou+cs*3; end
else begin ou:=ou*10*10*10; end;
clYellow: if i<4 then begin ou:=ou+cs*4; end
else begin ou:=ou*10*10*10*10; end;
clGreen : if i<4 then begin ou:=ou+cs*5; end
else begin ou:=ou*10*10*10*10*10; end;
clBlue : if i<4 then begin ou:=ou+cs*6; end
else begin ou:=ou*10*10*10*10*10*10; end;
clPurple: if i<4 then begin ou:=ou+cs*7; end
else begin ou:=ou*10*10*10*10*10*10*10; end;
clGray: if i<4 then begin ou:=ou+cs*8; end
else begin ou:=ou*10*10*10*10*10*10*10*10; end;
clwhite: if i<4 then begin ou:=ou+cs*9; end
else begin ou:=ou*10*10*10*10*10*10*10*10*10; end;
clBlack: if i<>4 then begin ou:=ou; end
else begin bj:=0; end;
clSilver: begin jd:=10; bj:=1; end;
clOlive: begin jd:=5; bj:=1; end;
end;
end; //2
js2:=ou;
end; //1

procedure TForm1.FormCreate(Sender: TObject);
var
a:cardinal;
begin
a:=clMaroon;
ColorBox1.Items.AddObject('棕色',TObject(a));
ColorBox2.Items.AddObject('棕色',TObject(a));
ColorBox3.Items.AddObject('棕色',TObject(a));
ColorBox4.Items.AddObject('棕色',TObject(a));
ColorBox5.Items.AddObject('棕色',TObject(a));
ColorBox6.Items.AddObject('棕色',TObject(a));
ColorBox7.Items.AddObject('棕色',TObject(a));
ColorBox8.Items.AddObject('棕色',TObject(a));
ColorBox9.Items.AddObject('棕色',TObject(a));
a:=clRed;
ColorBox1.Items.AddObject('红色',TObject(a));
ColorBox2.Items.AddObject('红色',TObject(a));
ColorBox3.Items.AddObject('红色',TObject(a));
ColorBox5.Items.AddObject('红色',TObject(a));
ColorBox6.Items.AddObject('红色',TObject(a));
ColorBox7.Items.AddObject('红色',TObject(a));
ColorBox8.Items.AddObject('红色',TObject(a));
a:=clLime;
ColorBox1.Items.AddObject('酸橙色',TObject(a));
ColorBox2.Items.AddObject('酸橙色',TObject(a));
ColorBox3.Items.AddObject('酸橙色',TObject(a));
ColorBox5.Items.AddObject('酸橙色',TObject(a));
ColorBox6.Items.AddObject('酸橙色',TObject(a));
ColorBox7.Items.AddObject('酸橙色',TObject(a));
ColorBox8.Items.AddObject('酸橙色',TObject(a));

a:=clYellow;
ColorBox1.Items.AddObject('黄色',TObject(a));
ColorBox2.Items.AddObject('黄色',TObject(a));
ColorBox3.Items.AddObject('黄色',TObject(a));
ColorBox5.Items.AddObject('黄色',TObject(a));
ColorBox6.Items.AddObject('黄色',TObject(a));
ColorBox7.Items.AddObject('黄色',TObject(a));
ColorBox8.Items.AddObject('黄色',TObject(a));
a:=clGreen;
ColorBox1.Items.AddObject('绿色',TObject(a));
ColorBox2.Items.AddObject('绿色',TObject(a));
ColorBox3.Items.AddObject('绿色',TObject(a));
ColorBox5.Items.AddObject('绿色',TObject(a));
ColorBox6.Items.AddObject('绿色',TObject(a));
ColorBox7.Items.AddObject('绿色',TObject(a));
ColorBox8.Items.AddObject('绿色',TObject(a));
a:=clBlue;
ColorBox1.Items.AddObject('蓝色',TObject(a));
ColorBox2.Items.AddObject('蓝色',TObject(a));
ColorBox3.Items.AddObject('蓝色',TObject(a));
ColorBox5.Items.AddObject('蓝色',TObject(a));
ColorBox6.Items.AddObject('蓝色',TObject(a));
ColorBox7.Items.AddObject('蓝色',TObject(a));
ColorBox8.Items.AddObject('蓝色',TObject(a));
a:=clPurple;
ColorBox1.Items.AddObject('紫色',TObject(a));
ColorBox2.Items.AddObject('紫色',TObject(a));
ColorBox3.Items.AddObject('紫色',TObject(a));
ColorBox5.Items.AddObject('紫色',TObject(a));
ColorBox6.Items.AddObject('紫色',TObject(a));
ColorBox7.Items.AddObject('紫色',TObject(a));
ColorBox8.Items.AddObject('紫色',TObject(a));
a:=clGray;
ColorBox1.Items.AddObject('灰色',TObject(a));
ColorBox2.Items.AddObject('灰色',TObject(a));
ColorBox3.Items.AddObject('灰色',TObject(a));
ColorBox5.Items.AddObject('灰色',TObject(a));
ColorBox6.Items.AddObject('灰色',TObject(a));
ColorBox7.Items.AddObject('灰色',TObject(a));
ColorBox8.Items.AddObject('灰色',TObject(a));
a:=clwhite;
ColorBox1.Items.AddObject('白色',TObject(a));
ColorBox2.Items.AddObject('白色',TObject(a));
ColorBox3.Items.AddObject('白色',TObject(a));
ColorBox5.Items.AddObject('白色',TObject(a));
ColorBox6.Items.AddObject('白色',TObject(a));
ColorBox7.Items.AddObject('白色',TObject(a));
ColorBox8.Items.AddObject('白色',TObject(a));
a:=clBlack;
ColorBox1.Items.AddObject('黑色',TObject(a));
ColorBox2.Items.AddObject('黑色',TObject(a));
ColorBox3.Items.AddObject('黑色',TObject(a));
ColorBox4.Items.AddObject('黑色',TObject(a));
ColorBox5.Items.AddObject('黑色',TObject(a));
ColorBox6.Items.AddObject('黑色',TObject(a));
ColorBox7.Items.AddObject('黑色',TObject(a));
ColorBox8.Items.AddObject('黑色',TObject(a));
ColorBox9.Items.AddObject('黑色',TObject(a));
a:=clOlive;
colorbox4.Items.AddObject('金色',tobject(a));
colorbox9.Items.AddObject('金色',tobject(a));
a:=clSilver;
ColorBox4.Items.AddObject('银色',TObject(a));
colorbox9.Items.AddObject('银色',tobject(a));
Colorbox1.ItemIndex:=0;
radiobutton1.Checked:=true;
radiobutton2.Checked:=false;
sw:=1;
uw:=0;
end;



procedure TForm1.ColorBox1Change(Sender: TObject);
begin
shape3.Brush.Col

or:=colorbox1.Selected;
zf1[1]:=colorbox1.selected;
jg:=js1(zf1);
if jg<100000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<100000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.ColorBox2Change(Sender: TObject);
begin
shape4.Brush.Color:=colorbox2.Selected;
zf1[2]:=colorbox2.selected;
jg:=js1(zf1);
if jg<100000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<100000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.ColorBox3Change(Sender: TObject);
begin
shape5.Brush.Color:=colorbox3.Selected;
zf1[3]:=colorbox3.selected;
jg:=js1(zf1);
if jg<100000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<100000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.ColorBox4Change(Sender: TObject);
begin
shape6.Brush.Color:=colorbox4.Selected;
zf1[4]:=colorbox4.selected;
jg:=js1(zf1);
if jg<10000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<1000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.RadioButton1Click(Sender: TObject);

begin
radiobutton2.Checked:=false;
shape2.Visible:=false;
colorbox1.Selected:=clBlack;
shape3.Brush.Color:=colorbox1.Selected;
colorbox2.Selected:=clBlack;
shape4.Brush.Color:=colorbox2.Selected;
colorbox3.Selected:=clBlack;
shape5.Brush.Color:=colorbox3.Selected;
colorbox4.Selected:=clBlack;
shape6.Brush.Color:=colorbox4.Selected;
colorbox5.Selected:=clBlack;
shape2.Brush.Color:=colorbox5.Selected;
colorbox6.Selected:=clBlack;
shape3.Brush.Color:=colorbox6.Selected;
colorbox7.Selected:=clBlack;
shape4.Brush.Color:=colorbox7.Selected;
colorbox8.Selected:=clBlack;
shape5.Brush.Color:=colorbox8.Selected;
colorbox9.Selected:=clBlack;
shape6.Brush.Color:=colorbox9.Selected;
zf1[1]:=colorbox1.selected;
zf1[2]:=colorbox2.selected;
zf1[3]:=colorbox3.selected;
zf1[4]:=colorbox4.selected;
colorbox1.Enabled:=true;
colorbox2.Enabled:=true;
colorbox3.Enabled:=true;
colorbox4.Enabled:=true;
colorbox5.Enabled:=false;
colorbox6.Enabled:=false;
colorbox7.Enabled:=false;
colorbox8.Enabled:=false;
colorbox9.Enabled:=false;
sw:=1;
uw:=0;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
radiobutton1.checked:=false;
shape2.Visible:=true;
colorbox1.Selected:=clBlack;
shape3.Brush.Color:=colorbox1.Selected;
colorbox2.Selected:=clBlack;
shape4.Brush.Color:=colorbox2.Selected;
colorbox3.Selected:=clBlack;
shape5.Brush.Color:=colorbox3.Selected;
colorbox4.Selected:=clBlack;
shape6.

Brush.Color:=colorbox4.Selected;
colorbox5.Selected:=clBlack;
shape2.Brush.Color:=colorbox5.Selected;
colorbox6.Selected:=clBlack;
shape3.Brush.Color:=colorbox6.Selected;
colorbox7.Selected:=clBlack;
shape4.Brush.Color:=colorbox7.Selected;
colorbox8.Selected:=clBlack;
shape5.Brush.Color:=colorbox8.Selected;
colorbox9.Selected:=clBlack;
shape6.Brush.Color:=colorbox9.Selected;
zf1[1]:=colorbox1.selected;
zf1[2]:=colorbox2.selected;
zf1[3]:=colorbox3.selected;
zf1[4]:=colorbox4.selected;
colorbox1.Enabled:=false;
colorbox2.Enabled:=false;
colorbox3.Enabled:=false;
colorbox4.Enabled:=false;
colorbox5.Enabled:=true;
colorbox6.Enabled:=true;
colorbox7.Enabled:=true;
colorbox8.Enabled:=true;
colorbox9.Enabled:=true;
sw:=0;
uw:=1;
end;

procedure TForm1.ColorBox5Change(Sender: TObject);
begin
shape2.Brush.Color:=colorbox5.Selected;
zf1[1]:=colorbox5.selected;
jg:=js2(zf1);
if jg<100000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<10000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.ColorBox6Change(Sender: TObject);
begin
shape3.Brush.Color:=colorbox6.Selected;
zf1[2]:=colorbox6.selected;
jg:=js2(zf1);
if jg<100000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<10000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.ColorBox7Change(Sender: TObject);
begin
shape4.Brush.Color:=colorbox7.Selected;
zf1[3]:=colorbox7.selected;
jg:=js2(zf1);
if jg<100000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<10000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.ColorBox8Change(Sender: TObject);
begin
shape5.Brush.Color:=colorbox8.Selected;
zf1[4]:=colorbox8.selected;
jg:=js2(zf1);
if jg<100000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<10000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.ColorBox9Change(Sender: TObject);
begin
shape6.Brush.Color:=colorbox9.Selected;
zf1[5]:=colorbox9.selected;
jg:=js2(zf1);
if jg<100000 then
edit1.Text:=floattostr(jg)+' 欧'
else if jg<10000000 then
edit1.text:=floattostr(jg/1000)+'K 欧'
else
edit1.text:=floattostr(jg/1000000)+'M 欧';
edit2.Text:='+/- '+floattostr(jd)+'%';
if bj=0 then
edit2.Clear;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
colorbox1.Selected:=clBlack;
shape3.Brush.Color:=colorbox1.Selected;
colorbox2.Selected:=clBlack;
shape4.Brush.Color:=colorbox2.Selected;
colorbox3.Selected:=clBlack;
shape5.Brush.Color:=color

box3.Selected;
colorbox4.Selected:=clBlack;
shape6.Brush.Color:=colorbox4.Selected;
colorbox5.Selected:=clBlack;
shape2.Brush.Color:=colorbox5.Selected;
colorbox6.Selected:=clBlack;
shape3.Brush.Color:=colorbox6.Selected;
colorbox7.Selected:=clBlack;
shape4.Brush.Color:=colorbox7.Selected;
colorbox8.Selected:=clBlack;
shape5.Brush.Color:=colorbox8.Selected;
colorbox9.Selected:=clBlack;
shape6.Brush.Color:=colorbox9.Selected;
zf1[1]:=colorbox1.selected;
zf1[2]:=colorbox2.selected;
zf1[3]:=colorbox3.selected;
zf1[4]:=colorbox4.selected;
if sw=1 then
edit1.Text:=floattostr(js1(zf1));
if uw=1 then
edit1.Text:=floattostr(js1(zf1));
edit2.Text:='+/- '+floattostr(jd)+'%';
edit2.Clear;
end;

end.

相关文档