دلفي تعليم
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

هذا الكود يحول بعض خصائص كل العناصر الموضوعة على النموذج (Form) الى كود برمجي .

اذهب الى الأسفل

هذا الكود يحول بعض خصائص كل العناصر الموضوعة على النموذج (Form) الى كود برمجي .  Empty هذا الكود يحول بعض خصائص كل العناصر الموضوعة على النموذج (Form) الى كود برمجي .

مُساهمة  djelal 18/9/2020, 9:57 pm

Delphi
كود دلفي

هذا الكود يحول بعض خصائص كل العناصر الموضوعة على النموذج (Form) الى كود برمجي .

أولا:
الطريقة هي ضع كل العناصر على الفورم ورتبهم  بشكل الذي تريده  .
ثم ضع ميمو على الفورم و نفذ الكود سيعرض في الميمو خصائص كل العناصر الموضوعة على الفورم و التي تم تحديدها في الكود.
ثانيا:
انسخ الكود الناتج في الميمو والصقه في الاجراء بوتو مثلا  وضع العناصر على الفورم بشكل عشوائ و نفذ برنامج واضغط فوق البوتو
وشاهد كيف يرتب كما رتبتهم في المرة السابقة

ملاحظة
يجب تعديل حسب العناصر الموجودة عندك

الكود:

uses
   Unit2;

procedure TForm1.Button1Click(Sender: TObject);
const
 t01:array[0..10] of String =

('mrNone','mrOk','mrCancel','mrAbort','mrRetry',
  'mrIgnore','mrYes','mrNo','mrAll','mrNoToAll','mrYesToAll');
 t02 :array[0..10] of String = ('bkCustom', 'bkOK', 'bkCancel',

'bkHelp',
  'bkYes', 'bkNo', 'bkClose','bkAbort', 'bkRetry', 'bkIgnore',

'bkAll');
 t03:array[0..3] of String = ('blGlyphLeft', 'blGlyphRight',

'blGlyphTop', 'blGlyphBottom');
  CBiDiMode:array[0..3] of String = ('bdLeftToRight',

'bdRightToLeft', 'bdRightToLeftNoAlign',
    'bdRightToLeftReadingOnly');
 t05: array[0..1] of String = ('htKeyword', 'htContext');
 CAlignTab: array[0..6] of String  = ('alNone', 'alTop',

'alBottom', 'alLeft',
 'alRight', 'alClient', 'alCustom');
  CAlignmentTab: array[0..2] of String = ('taLeftJustify',

'taRightJustify', 'taCenter');
 CTextLayoutTab: array[0..2] of String = ('tlTop', 'tlCenter',

'tlBottom');
 CEditCharCaseTab: array[0..2] of String = ('ecNormal',

'ecUpperCase', 'ecLowerCase');
 CFontStyleTab: array[0..4] of String = ('[fsBold]', '[fsItalic]',

'[fsUnderline]', '[fsStrikeOut]', '[]');
 CBorderStyleTab: array[0..1] of String = ('bsNone','bsSingle');
 CFormBorderStyleTab: array[0..5] of String = ('bsNone',

'bsSingle', 'bsSizeable', 'bsDialog',
  'bsToolWindow', 'bsSizeToolWin');
 CPositionTab: array[0..7] of String = ('poDesigned', 'poDefault',
   'poDefaultPosOnly', 'poDefaultSizeOnly','poScreenCenter',
   'poDesktopCenter', 'poMainFormCenter', 'poOwnerFormCenter');

var
 i: integer;
 Ed1: TEdit;
 Butn: TButton;
 lbl1: TLabel;
 BBtn: TBitBtn;
 WinControl1: TWinControl;
 CustomEdit1: TCustomEdit;
  
begin
 Memo1.Clear;
 Memo1.Lines.Add('Caption:='''+Caption+''';');
 Memo1.Lines.Add('BiDiMode:='+CBiDiMode[GBiDiMode(BiDiMode)]+';');
 Memo1.Lines.Add('font.charset:='+IntToStr(Font.Charset)+';');
 Memo1.Lines.Add('font.name:='''+Font.Name+''';');
 Memo1.Lines.Add('Left := '+inttostr(Left)+';');
 Memo1.Lines.Add('Top := '+inttostr(Top)+';');
 Memo1.Lines.Add('Height := '+inttostr(Height)+';');
 Memo1.Lines.Add('Width := '+inttostr(Width)+';');
 Memo1.Lines.Add('Position:='+CPositionTab[GPositions(Position)]

+';');
 Memo1.Lines.Add('BorderStyle:='+CFormBorderStyleTab

[GFormBorderStyles(BorderStyle)]+';');
 Memo1.Lines.Add('BorderWidth:='+inttostr(BorderWidth)+';');
 Memo1.Lines.Add('font.Style:='+CFontStyleTab[GFontStyless

(Font.Style)]+';');
 Memo1.Lines.Add('');
 with Memo1.Lines do
  for i := 0 to ComponentCount-1 do
  begin                                      
   Add(Components[i].Name+'.Name := '''+Components[i].Name+''';');
   Add(Components[i].Name+'.Left := '+IntToStr(Controls[i].Left)

+';');
   Add(Components[i].Name+'.Top := '+IntToStr(Controls[i].Top)

+';');
   Add(Components[i].Name+'.Height := '+IntToStr(Controls

[i].Height)+';');
   Add(Components[i].Name+'.Width := '+IntToStr(Controls[i].Width)

+';');
   Add(Components[i].Name+'.BiDiMode:= '+CBiDiMode[GBiDiMode

(Controls[i].BiDiMode)]+';');
   Add(Components[i].Name+'.Cursor := '+CursorToString(Controls

[i].Cursor)+';');
   Add(Components[i].Name+'.HelpContext := '+IntToStr(Controls

[i].HelpContext)+';');
   Add(Components[i].Name+'.HelpType := '+t05[GHelpType(Controls

[i].HelpType)]+';');
   Add(Components[i].Name+'.HelpKeyword := '''+Controls

[i].HelpKeyword+''';');
   Add(Components[i].Name+'.Enabled := '+BoolToStr(Controls

[i].Enabled, True)+';');
   Add(Components[i].Name+'.Hint := '''+Controls[i].Hint+''';');
   Add(Components[i].Name+'.ShowHint := '+BoolToStr(Controls

[i].ShowHint, True)+';');
   Add(Components[i].Name+'.Tag := '+IntToStr(Controls[i].Tag)

+';');
   Add(Components[i].Name+'.Align := '+CAlignTab[GAligns(Controls

[i].Align)]+';');
   Add(Components[i].Name+'.Visible := '+BoolToStr(Controls

[i].Visible, True)+';');
   if Components[i] is TWinControl then
   begin
    WinControl1 := Components[i] as TWinControl;
    Add(Components[i].Name+'.TabOrder := '+IntToStr

(WinControl1.TabOrder)+';');
    Add(Components[i].Name+'.TabStop := '+BoolToStr

(WinControl1.TabStop, True)+';');
   end;
   if Components[i] is TLabel then
   begin
    lbl1 := Components[i] as TLabel;
    Add(Components[i].Name+'.Caption := '''+lbl1.Caption+''';');
    Add(Components[i].Name+'.Color := '+ColorToString(lbl1.Color)

+';');
    Add(Components[i].Name+'.Font.Name :=

'''+lbl1.Font.Name+''';');
    Add(Components[i].Name+'.Font.Charset := '+IntToStr

(lbl1.Font.Charset)+';');
    Add(Components[i].Name+'.Font.Color := '+ColorToString

(lbl1.Font.Color)+';');
    Add(Components[i].Name+'.Font.Size := '+IntToStr

(lbl1.Font.Size)+';');
    Add(Components[i].Name+'.Font.Style := '+CFontStyleTab

[GFontStyless(lbl1.Font.Style)]+';');
    Add(Components[i].Name+'.Alignment := '+CAlignmentTab

[GAlignments(lbl1.Alignment)]+';');
    Add(Components[i].Name+'.Layout := '+CTextLayoutTab

[GTextLayouts(lbl1.Layout)]+';');
    Add(Components[i].Name+'.AutoSize := '+BoolToStr(lbl1.AutoSize,

True)+';');
    Add(Components[i].Name+'.ParentBiDiMode := '+BoolToStr

(lbl1.ParentBiDiMode, True)+';');
    Add(Components[i].Name+'.ParentColor := '+BoolToStr

(lbl1.ParentColor, True)+';');
    Add(Components[i].Name+'.ParentFont := '+BoolToStr

(lbl1.ParentFont, True)+';');
    Add(Components[i].Name+'.ParentShowHint := '+BoolToStr

(lbl1.ParentShowHint, True)+';');
    Add(Components[i].Name+'.ShowAccelChar := '+BoolToStr

(lbl1.ShowAccelChar, True)+';');
    Add(Components[i].Name+'.Transparent := '+BoolToStr

(lbl1.Transparent, True)+';');
    Add(Components[i].Name+'.WordWrap := '+BoolToStr(lbl1.WordWrap,

True)+';');
   end;
   if Components[i] is TEdit then
   begin
    Ed1 := Components[i] as TEdit;
    Add(Components[i].Name+'.Text := '''+Ed1.Text+''';');
    Add(Components[i].Name+'.PasswordChar := '+GPasswordChars(Ed1)

+';');
    Add(Components[i].Name+'.Color := '+ColorToString(Ed1.Color)

+';');
    Add(Components[i].Name+'.Font.Name := '''+Ed1.Font.Name+''';');
    Add(Components[i].Name+'.Font.Charset := '+IntToStr

(lbl1.Font.Charset)+';');
    Add(Components[i].Name+'.Font.Color := '+ColorToString

(Ed1.Font.Color)+';');
    Add(Components[i].Name+'.Font.Size := '+IntToStr

(Ed1.Font.Size)+';');
    Add(Components[i].Name+'.MaxLength := '+IntToStr

(Ed1.MaxLength)+';');
    Add(Components[i].Name+'.BorderStyle := '+CBorderStyleTab

[GBorderStyles(Ed1.BorderStyle)]+';');
    Add(Components[i].Name+'.Font.Style := '+CFontStyleTab

[GFontStyless(lbl1.Font.Style)]+';');
    Add(Components[i].Name+'.CharCase:= '+CEditCharCaseTab

[GEditCharCases(Ed1.CharCase)]+';');
    Add(Components[i].Name+'.MaxLength := '+IntToStr

(Ed1.MaxLength)+';');
    Add(Components[i].Name+'.AutoSelect := '+BoolToStr

(Ed1.AutoSelect, True)+';');
    Add(Components[i].Name+'.ReadOnly := '+BoolToStr(Ed1.ReadOnly,

True)+';');
    Add(Components[i].Name+'.AutoSize := '+BoolToStr(Ed1.AutoSize,

True)+';');
    Add(Components[i].Name+'.HideSelection := '+BoolToStr

(Ed1.HideSelection, True)+';');
    Add(Components[i].Name+'.ParentBiDiMode := '+BoolToStr

(Ed1.ParentBiDiMode, True)+';');
    Add(Components[i].Name+'.ParentColor := '+BoolToStr

(Ed1.ParentColor, True)+';');
    Add(Components[i].Name+'.ParentFont := '+BoolToStr

(Ed1.ParentFont, True)+';');
    Add(Components[i].Name+'.ParentShowHint := '+BoolToStr

(Ed1.ParentShowHint, True)+';');
   end;
   if Components[i] is TButton then
   begin
    Butn := Components[i] as TButton;
    Add(Components[i].Name+'.Caption := '''+Butn.Caption+''';');
    Add(Components[i].Name+'.Font.Name :=

'''+Butn.Font.Name+''';');
    Add(Components[i].Name+'.Font.Charset := '+IntToStr

(Butn.Font.Charset)+';');
    Add(Components[i].Name+'.Font.Color := '+ColorToString

(Butn.Font.Color)+';');
    Add(Components[i].Name+'.Font.Size := '+IntToStr

(Butn.Font.Size)+';');
    Add(Components[i].Name+'.Font.Style := '+CFontStyleTab

[GFontStyless(Butn.Font.Style)]+';');
    Add(Components[i].Name+'.ModalResult := '+t01

[Butn.ModalResult]+';');
    Add(Components[i].Name+'.Cancel := '+BoolToStr(Butn.Cancel,

True)+';');
    Add(Components[i].Name+'.ParentBiDiMode := '+BoolToStr

(Butn.ParentBiDiMode, True)+';');
    Add(Components[i].Name+'.ParentFont := '+BoolToStr

(Butn.ParentFont, True)+';');
    Add(Components[i].Name+'.ParentShowHint := '+BoolToStr

(Butn.ParentShowHint, True)+';');
    Add(Components[i].Name+'.WordWrap := '+BoolToStr(Butn.WordWrap,

True)+';');
    if Components[i] is TBitBtn then
    begin
     Bbtn := Components[i] as TBitBtn;
     Add(Components[i].Name+'.NumGlyphs := '+IntToStr

(Bbtn.NumGlyphs)+';');
     Add(Components[i].Name+'.Kind := '+t02[GKind(Bbtn.Kind)]+';');
     Add(Components[i].Name+'.Layout := '+t03[GLayout

(Bbtn.Layout)]+';');
    end;
   end;
  end;
end;
الوحدة الثانية


الكود:

unit Unit2;

interface

uses
  Classes, Graphics, Controls, StdCtrls,  Forms,
  Buttons;
  
    function GKind(Kinde: TBitBtnKind): Integer;
    function GLayout(Layout1: TButtonLayout): Integer;
    function GHelpType(HelpType1: THelpType): Integer;
    function GBiDiMode(BiDiMode1: TBiDiMode): Integer;
    function GAligns(Align1: TAlign): Integer;
    function GAlignments(Alignment1: TAlignment): Integer;
    function GTextLayouts(TextLayout1: TTextLayout): Integer;
    function GEditCharCases(EditCharCase1: TEditCharCase): Integer;
    function GFontStyless(FontStyles1: TFontStyles): Integer;
    function GBorderStyles(BorderStyle1: TBorderStyle): Integer;
    function GPasswordChars(edt: TEdit): string;
    function GFormBorderStyles(FormBorderStyle1: TFormBorderStyle):

Integer;
    function GPositions(Position1: TPosition): Integer;

implementation

function GKind;
begin
     case Kinde of
       bkCustom: Result := 0;
       bkOK: Result := 1;
       bkCancel: Result := 2;
       bkHelp: Result := 3;
       bkYes: Result := 4;
       bkNo: Result := 5;
       bkClose: Result := 6;
       bkAbort: Result := 7;
       bkRetry: Result := 8;
       bkIgnore: Result :=9 ;
       bkAll: Result := 10;
     end;
end;

function GLayout;
begin
     case Layout1 of
       blGlyphLeft: Result:=0;
       blGlyphRight: Result:=1;
       blGlyphTop: Result:=2;
       blGlyphBottom: Result:=3;
     end;
end;

function GHelpType(HelpType1: THelpType): Integer;
begin    //htContext
  if HelpType1 = htKeyword then Result := 0 else Result := 1;
end;

function GBiDiMode(BiDiMode1: TBiDiMode): Integer;
begin
 case BiDiMode1 of
  bdLeftToRight: Result:=0; bdRightToLeft: Result:=1;
  bdRightToLeftNoAlign: Result:=2;
  bdRightToLeftReadingOnly: Result:=3;
 end;
end;

function GAligns(Align1: TAlign): Integer;
begin
 case Align1 of
  alNone: Result:=0;   alTop: Result:=1; alBottom: Result:=2;
  alLeft: Result:=3; alRight: Result:=4; alClient: Result:=5;
  alCustom: Result:=0;
 end;
end;

function GAlignments(
  Alignment1: TAlignment): Integer;
begin
 case Alignment1 of
  taLeftJustify: Result:=0; taRightJustify: Result:=1;
  taCenter: Result:=2;
 end;
end;

function GTextLayouts(
  TextLayout1: TTextLayout): Integer;
begin
 case TextLayout1 of
  tlTop: Result:=0; tlCenter: Result:=1; tlBottom: Result:=2;
 end;
end;

function GEditCharCases(
  EditCharCase1: TEditCharCase): Integer;
begin
 case EditCharCase1 of
  ecNormal: Result:=0; ecUpperCase: Result:=1;
  ecLowerCase: Result:=2;
 end;
end;

function GFontStyless(
  FontStyles1: TFontStyles): Integer;
begin
  if FontStyles1 = [fsBold] then Result:=0
  else if FontStyles1 = [fsItalic] then Result:=1
  else if FontStyles1 = [fsUnderline] then Result:=2
  else if FontStyles1 = [fsStrikeOut] then Result:=3 else

Result:=4;
end;

function GBorderStyles(
  BorderStyle1: TBorderStyle): Integer;
begin
  case BorderStyle1 of
    bsNone: Result:=0;
    bsSingle: Result:=1;
  end;
end;

function GPasswordChars(edt: TEdit): string;
begin
  if edt.PasswordChar='*' then Result:='*'
  else Result:='#0';
end;

function GFormBorderStyles(
  FormBorderStyle1: TFormBorderStyle): Integer;
begin
 case FormBorderStyle1 of
  bsNone: Result:=0;
  bsSingle: Result:=1;
  bsSizeable: Result:=2;
  bsDialog: Result:=3;
  bsToolWindow: Result:=4;
  bsSizeToolWin: Result:=5;
 end;
end;

function GPositions(Position1: TPosition): Integer;
begin
 case Position1 of
  poDesigned: Result:=0;
  poDefault: Result:=1;
  poDefaultPosOnly: Result:=2;
  poDefaultSizeOnly: Result:=3;
  poScreenCenter: Result:=4;
  poDesktopCenter: Result:=5;
  poMainFormCenter: Result:=6;
  poOwnerFormCenter: Result:=7;
 end;
end;

end.


ملاحظة:
اذا اردت ان تنشئ العناصر برمجيا استعمل هذه الطرقة

الكود:

//uses ExtCtrls, StdCtrls;
procedure TForm1.FormCreate(Sender: TObject);
var Button1: tButton;
begin
Button1:= tButton.Create(self);
[ندعوك للتسجيل في المنتدى أو التعريف بنفسك لمعاينة هذا الرابط] := Form1;
Button1.Parent := Panel1;
[ندعوك للتسجيل في المنتدى أو التعريف بنفسك لمعاينة هذا الرابط] := GroupBox1;
end;

djelal
مبرمج مجتهد

عدد المساهمات : 157
تاريخ التسجيل : 29/04/2015

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

- مواضيع مماثلة

 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى