我有一個問題,當我去添加更多的「名稱」的if語句。我很難看到那裏是否準備好了。因此,是否有一個更乾淨的方式來寫這個在哪裏我可以很容易地看到什麼名字都讀在那裏?寫所有這些if語句清理器
function TfDB.GetW(name: string) :integer;
begin
result := 0;
if (name = 'Destacker') or (name='Router') or (name = 'Turn Table') Then
result := 57;
if (name = 'Laser Marker') then
result := 66;
if (name = 'SP28')OR(name='Chamber') OR (name = 'CM402') OR (name = 'SP60') then
result := 65;
if (name = 'Conveyor') OR (name = 'Slide Gate') OR (name = 'Washer') then
result := 51;
if (name = 'BTU') OR (name = 'Furukawa') OR (name = 'Radial') OR (name = 'HDP') or (name = 'MSR') OR (name = 'Koki') Or (name = 'MSF') then
result := 98;
if (name = 'Buffer')OR (name = 'Reclaimer') OR (name = 'ECO Roller') then
result := 49;
if (name = 'Inverter') or (name = 'CNC') then
result := 42;
if (name = '3-D Check Station') or (name='Screw Machine') or (name='VT-Win') or(name='Component Viewer') then
result := 58;
if (name = 'AOI Panel') or (name='AirBlow') then
result := 42;
if (name='Mag Loader') or (name='Soltec') then
result := 73;
if (name='Tester') then
result := 33;
if (name='LoadBox') then
result := 17;
if (name = 'DeltaWave') then
result := 89;
if (name = 'ScrewFeeder') then
result := 25;
if (name='Pump') then
result := 33;
//if result is 0 show message error.
end;
我認爲你應該使用數據庫或者至少一個INI才能在未來編輯,硬編碼可能不是一個好主意。 – ComputerSaysNo
它使用一個數據庫,它抓住一個機器(泵)的名稱,並給它一個33的形狀大小..但是,如果我想要改變一臺機器的大小或增加新的機器尺寸,那麼我必須要更改。但只是發現這更容易。 –