TActionManager ที่อยู่ใน Delphi 2010 มีการใช้งานคล้ายกับ TActionList ใน Delphi Version ก่อนๆ จะแต่งต่างกันตรงที่มีประสิทธิภาพ และยืดหยุ่นมากกว่า
TActionManager หรือ TActionList เป็น Component ที่ใช้สำหรับจัดการการพัฒนาโปรแกรมเป็นหลัก ไม่ใช่เทคโนโลยีใดๆ ที่ทำให้โปรแกรมมีประสิทธิภาพมากขึ้น เป็นการบริหาร Event method ต่างๆในโปรแกรมที่อาจจะใช้งาน method ซ้ำๆกัน
 |
Component Action Manager จะอยู่ใน Tab Additional |
ผู้เขียนจะทำตัวอย่างง่ายๆเพื่อให้เข้าใจ โดยตัวอย่างแรกจะทำการสร้าง Event ขึ้นโดย VCL Action Manager
จะให้ปุ่มทำงานกับ Action method ที่สร้างเอาไว้
 |
บนฟอร์มประกอบด้วย TEdit , TButton และ TActionManager |
 |
คลิ๊กเมาส์ปุ่มขวาที่ Component ActionManager แล้วเลือก Customize |
 |
หน้าต่าง Editing ของ ActionManager ใน Tab Actions ให้เลือก New Action เพื่อเพิ่ม Action ตามภาพ |
 |
เปลี่ยน Name และ Cation ของ Action ที่สร้างขึ้นเป็น ShowText |
 |
ใน Tab Events ให้สร้าง Action method OnExecute ขึ้นมา |
ภายใน method ShowTextExecute ที่สร้างขึ้นใส่ คำสั่งให้แสดงค่าของ Edit บนฟอร์ม
procedure TForm1.ShowTextExecute(Sender: TObject);
begin
ShowMessage(Self.Edit1.Text);
end;
 |
ไปที่ Property Action ของปุ่ม Show Text แล้วเลือกให้ใช้ Action method ShowText ที่สร้างโดย ActionManager |
 |
เมื่อทดสอบโดยกดปุ่ม ปุ่ม ShowText จะไปทำงานที่ Action ShowText แทน Event OnClick |
อีกตัวอย่างนึงคือ การสร้างปุ่มให้ทำงานได้แบบไม่ต้องเขียนคำสั่งใดๆ ซึ่งเป็นความสามารถที่เพิ่มขึ้นมา
ตัวอย่างนี้ผู้เขียนจะทำการแสดงภาพโดยใช้ Action Manager เข้ามาช่วย
 |
Component ที่ใช้คือ TImage , TButton และ TActionManager |
 |
กำหนด Action ของปุ่ม เลือก New Standard Action > Dialog > TOpenPicture |
 |
เมื่อเปิดหน้าต่าง Editing ของ ActionManager ดูก็จะพบว่ามีการสร้าง Action Open Picture ให้อัตโนมัติ แต่ยังไม่สามารถทำงานได้ จนกว่าจะสร้าง Action method ที่ OnAccept |
ใน method OpenPicture1Accept ก็แค่ใส่คำสั่งนำ File Path ของรูปภาพมาแสดงใน TImage เท่านั้นเอง
procedure TForm1.OpenPicture1Accept(Sender: TObject);
begin
Self.Image1.Picture.LoadFromFile(Self.OpenPicture1.Dialog.FileName);
end;
 |
ทดสอบโดยกดปุ่ม Open Picture แล้วเลือกไฟล์รูปภาพเข้ามาแสดง |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น