procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char);
var
i, j, v_Start, v_End : Integer;
v_Str : String;
v_Return : Integer;
begin
if Key = #13 then
begin
Key := #0;
for j := 1 to Length(v_Str) do
begin
if Copy(v_Str,j,1) = '+' then
begin
for i := 0 to self.ComponentCount - 1 do
begin
if UpperCase(self.Components[i].Name) = Copy(v_Str,v_Start,v_End) then
begin
v_Return := v_Return + StrtoInt(TEdit(self.Components[i]).Text);
v_Start := v_Start + v_End + 1;
v_End := 0;
Break;
end;
end;
end
else
Inc(v_End);
end;
for i := 0 to self.ComponentCount - 1 do
begin
if UpperCase(self.Components[i].Name) = Copy(v_Str,v_Start,v_End) then
begin
v_Return := v_Return + StrtoInt(TEdit(self.Components[i]).Text);
Break;
end;
end;
var
FirstStr: string;
SecondStr: string;
tmpPos: integer;
SourceStr: string;
begin
SourceStr := StringReplace((Edit3.Text), ' ', '', [rfReplaceAll]);
tmpPos := Pos('+', SourceStr);
if tmpPos <= 0 then exit;
FirstStr := SearchFirstStr(tmpPos, SourceStr);
SecondStr := SearchSecondStr(tmpPos, SourceStr);
Edit4.Text := IntToStr(StrToInt(TEdit(FindComponent(FirstStr)).Text)
+ StrToInt(TEdit(FindComponent(SecondStr)).Text));
end;
function TForm1.SearchFirstStr(AtmpPos: integer; ASourceStr: string): string;
begin
result := StringReplace(Copy(ASourceStr, 1, AtmpPos -1), '.Text', '', [rfReplaceAll]);
end;
function TForm1.SearchSecondStr(AtmpPos: integer; ASourceStr: string): string;
begin
result := StringReplace(Copy(ASourceStr, AtmpPos + 1, Length(ASourceStr)
- (AtmpPos -1)), '.Text', '', [rfReplaceAll]);
end;