28 พฤษภาคม 2550

php: baaGrid::setGPCol

baaGrid เป็น Data Grid class ตัวหนึ่งซึ่งสามารถแสดงผล SQL Query จาก Database ได้หลายตัว โดย Default เป็น MySQL

ความสามารถหนึ่งที่ทำให้ baaGrid แสดงรายงานในแบบตารางได้ดีคือ General Purpose Column ซึ่งจะสามารถนำข้อมูลจาก query มาแสดงในรูปแบบอื่นได้เช่น image หรือ hyperlink แต่อย่างหนึ่งซึ่งตัว baaGrid Guide ไม่ได้บอกไว้ก็คือการสนับสนุนการใช้ function ได้ (**อย่างมีข้อจำกัด**) ทั้ง php built-in และ user defined โดยในการ parse funtion นั้น baaGrid ใช้ function_exists ของ php ตรวจอักขระที่ ตำแหน่ง 0 จนถึง วงเล็บเปิดแรก ถ้ามี function ที่รู้จักก็จะผ่านไปให้ eval ของ php ทำงาน
ตัวอย่าง
...
$grid->setGPCol(4, 'myfunction(#1)'); // pass column 1 from query to myfunction, valid for numeric data
$grid->setGPCol(5, 'myfunction("#2")'); // pass column 2 from query to myfunction, valid for string data
$grid->setGPCol(6, 'myfunction(#1)+123'); // also valid
...
$grid->setGPCol(6, '123+myfunction(#1)'); // invalid, function_exists('123+myfunction') returns null

11 พฤษภาคม 2550

wxWidgets ใช้ Image File แบบอื่นนอกเหนือ BMP

ถ้าจะใช้ Image File แบบอื่นนอกเหนือ BMP ต้องทำการระบุชนิดที่ต้องการใช้เพิ่มด้วยดังนี้
1 ใน class ที่ derived จาก wxApp ที่ OnInit จะต้องทำการ add image handler

#include

bool MyApp::OnInit() {
...
wxImage::AddHandler( new wxPNGHandler );
wxImage::AddHandler( new wxJPEGHandler );
wxImage::AddHandler( new wxGIFHandler );
wxImage::AddHandler( new wxXPMHandler );
}



ถ้าเอาทุกแบบใช้ wxInitAllImageHandlers.
Available Image Handlers

  • wxBMPHandler For loading and saving Windows bitmap files.
  • wxPNGHandler For loading and saving PNG files. Images with transparency or an alpha channel are supported.
  • wxJPEGHandler For loading and saving JPEG files.
  • wxGIFHandler GIF files: only for loading, due to legal issues.
  • wxPCXHandler For loading and saving PCX files. wxPCXHandler will count the number of different colors in the image; if there are 256 or fewer colors, it will save as 8-bit; otherwise it will save as 24-bit.
  • wxPNMHandler For loading and saving PNM files. Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format, wxPNMHandler will always save as raw RGB.
  • wxTIFFHandler For loading and saving TIFF files.
  • wxIFFHandler For loading IFF files.
  • wxXPMHandler For loading and saving XPM files.
  • wxICOHandler For loading and saving Windows icon files.
  • wxCURHandler For loading and saving Windows cursor files.
  • wxANIHandler For loading Windows animated cursor files.

2. อย่าลืม Link library ที่เกี่ยวข้อง

  • JPEG, wxjpeg.lib
  • PNG, wxpng.lib & wxzlib.lib