
Опытный
 
Профиль
Группа: Участник
Сообщений: 771
Регистрация: 23.2.2007
Репутация: нет Всего: 15
|
Я могу только описать один из своих нестандартных способов использования имени компонента для благих целей  ... Вообщем делаю форму с компонентами, от которой затем все наследуются, и в зависимости от имен компонентов на форме даю каждому свой функционал, знаете как удобно... и названия более менее приличные и над кодом постоянно не нужно задумываться... Вообщем я частенько использую названия компонентов в качестве обозначения их функционала... ну вот кусок: | Код | ... ... ... procedure TTActionForm.EditBtnClick(Sender: TObject); begin SelFiles.ShowModal; if SelFiles.ResEdit <> '' then TDMSEditBtn(Sender).Text := SelFiles.ResEdit; end;
procedure TTActionForm.EditBtnClick2(Sender: TObject); begin PropObj.ShowModal; if PropObj.ResEdit <> '' then TDMSEditBtn(Sender).Text := PropObj.ResEdit; end;
procedure TTActionForm.EditBtnClick3(Sender: TObject); begin obj_select.ShowModal; if ObjSelect <> '' then TDMSEditBtn(Sender).Text := ObjSelect; end;
function GetPrCom(Obj: TComponent; Self: TTActionForm): String; begin if GetPropInfo(Obj,'Text')<>nil then Result := GetPropValue(Obj,'Text') else if Obj Is TListBox then Result := TListBox(Obj).Items[TListBox(Obj).ItemIndex] else if Obj Is TComboBox then Result := TComboBox(Obj).Items[TComboBox(Obj).ItemIndex] else if Obj is TMemo then Result := StringReplace(TMemo(Obj).Text,#13#10,'\n',[rfReplaceAll,rfIgnoreCase]) else if Obj is TCheckBox then Result := BoolToStr(TCheckBox(Obj).Checked);
if ToAll then begin
if (Commas)and(Pos('cm',OBJ.Name)>0) then if Result='' then if TypeComma = 1 then Result := '''''' else Result := '""';
if (Commas)and( Pos('cm',OBJ.Name)>0) then if Result<>'' then
if TypeComma = 2 then begin if (Result[1]<>'"')and(Result[Length(Result)]<>'"') then Result := '"' + Result + '"'; end else begin if (Result[1]<>'''')and(Result[Length(Result)]<>'''') then Result := '''' + Result + ''''; end;
end else begin if (Self.Commas)and(Pos('cm',OBJ.Name)>0) then if Result='' then if Self.TypeComma = 1 then Result := '''''' else Result := '""';
if (Self.Commas)and( Pos('cm',OBJ.Name)>0) then if Result<>'' then
if Self.TypeComma = 2 then begin if (Result[1]<>'"')and(Result[Length(Result)]<>'"') then Result := '"' + Result + '"'; end else begin if (Result[1]<>'''')and(Result[Length(Result)]<>'''') then Result := '''' + Result + ''''; end;
end; end;
procedure SetParamValue(Obj: TComponent; Value: String); begin if (Pos('cm',OBJ.Name)>0)and(Commas) then Value := DelKav(Value); Value := StringReplace(Value,'\n',#13#10,[rfReplaceAll,rfIgnoreCase]);
if GetPropInfo(OBj,'Text')<>nil then begin SetPropValue(Obj,'Text',Value); exit; end; if Obj is TCheckBox Then begin TCheckBox(Obj).Checked := StrToBool(Value); exit; end; if Obj is TComboBox then begin TComboBox(Obj).ItemIndex := TComboBox(Obj).Items.IndexOf(Value); if TComboBox(Obj).Style = csDropDown then TComboBox(Obj).Text := Value; exit; end; if Obj is TListBox then begin TListBox(Obj).ItemHeight := TListBox(Obj).Items.IndexOf(Value); exit; end; TControl(Obj).SetTextBuf(PChar(Value)); end;
procedure TTActionForm.b_OkClick(Sender: TObject); Var I,PrInd: Integer; Nam: String; Frm: TForm; begin Inif.WriteInteger('Main','Left',Self.Left); Inif.WriteInteger('Main','Top',Self.Top); Inif.WriteInteger('Main','Width',Self.Width); Inif.WriteInteger('Main','Height',Self.Height); if not ToAll then begin Inif.WriteBool('Main','SaveOpt',Self.SaveOpt); Inif.WriteBool('Main','Commas',Self.Commas); Inif.WriteInteger('Main','TypeComma',Self.TypeComma); end; Frm := TForm(TControl(Sender).Owner); for i:=0 to Frm.ComponentCount-1 do begin Nam := UpperCase(Frm.Components[i].Name); if (Pos('PR',Nam)=1)and(Nam[3] in ['1'..'9']) then begin PrInd := StrToInt(Nam[3]); PR[PrInd] := GetPrCom(Frm.Components[i], TTActionForm(TControl(Sender).Owner)); end else if (Pos('OBJ1',Nam)=1) then begin ObjName := GetPrCom(Frm.Components[i], TTActionForm(TControl(Sender).Owner)) end; end; end;
procedure TTActionForm.FormActivate(Sender: TObject); Var I,Len,PrInd: Integer; Nam: String; begin b_Help.Visible := FileExists(ProgDir+'\Language\'+LocalLng+'\Help\'+ TComponent(Sender).Name+'.html');
ForceDirectories(ProgDir+'\Config'); Inif := TIniFile.Create(ProgDir + '\Config\' + Self.Name + '.ini');
Self.SaveOpt := Inif.ReadBool('Main','SaveOpt',True); if Self.SaveOpt then begin Self.Left := Inif.ReadInteger('Main','Left',Self.Left); Self.Top := Inif.ReadInteger('Main','Top',Self.Top); Self.Width := Inif.ReadInteger('Main','Width',Self.Width); Self.Height := Inif.ReadInteger('Main','Height',Self.Height); end;
Self.Commas := Inif.ReadBool('Main','Commas',True); Self.TypeComma := Inif.ReadInteger('Main','TypeComma',2);
if ResEdit <> '' then begin if PosSim(ResEdit,'(')>0 then begin ResEdit := GetInSkobka(ResEdit); Len := GetPRMCount(ResEdit,','); for i:=1 to Len do PR[I] := GetFastParam(ResEdit,I,',',True); end else begin PR[1] := CopyL(ResEdit,'='); ObjName := Copy(PR[1],1,Q_PosLastStr('.',PR[1])-1); PR[2] := CopyR(ResEdit,'='); end; end;
for i:=0 to Self.ComponentCount-1 do begin Nam := UpperCase(Self.Components[i].Name); if Pos('_DLG',Nam)>0 then begin TDMSEditBtn(Self.Components[i]).OnButtonClick := EditBtnClick; end; if Pos('_PROP',Nam)>0 then begin TDMSEditBtn(Self.Components[i]).OnButtonClick := EditBtnClick2; end; if Pos('_OBJ',Nam)>0 then begin TDMSEditBtn(Self.Components[i]).OnButtonClick := EditBtnClick3; end; if ResEdit <> '' then if (Pos('PR',Nam)=1)and(Nam[3] in ['1'..'9']) then begin PrInd := StrToInt(Nam[3]); SetParamValue(Self.Components[i],PR[PrInd]); end else if (Pos('OBJ1',Name)=1) then begin SetParamValue(Self.Components[i],ObjName); end; end;
end; ... ... ...
|
|