|
Wednesday, November 11, 2009
Mengirim Email dengan Delphi
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
edtSubject: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
edtNamaPengirim: TEdit;
edtEmailPengirim: TEdit;
Label4: TLabel;
edtNamaPenerima: TEdit;
edtEmailPenerima: TEdit;
Label5: TLabel;
MemoMessage: TMemo;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses MAPI;
{$R *.dfm}
function SendMail(const Subject, Body, FileName,
SenderName, SenderEMail,
RecipientName, RecipientEMail: string): Integer;
var
Message: TMapiMessage;
lpSender, lpRecipient: TMapiRecipDesc;
FileAttach: TMapiFileDesc;
SM: TFNMapiSendMail;
MAPIModule: HModule;
begin
FillChar(Message, SizeOf(Message), 0);
with Message do
begin
if (Subject <> '') then
lpszSubject := PChar(Subject);
if (Body <> '') then
lpszNoteText := PChar(Body);
if (SenderEmail <> '') then
begin
lpSender.ulRecipClass := MAPI_ORIG;
if (SenderName = '') then
lpSender.lpszName := PChar(SenderEMail)
else
lpSender.lpszName := PChar(SenderName);
lpSender.lpszAddress := PChar(SenderEmail);
lpSender.ulReserved := 0;
lpSender.ulEIDSize := 0;
lpSender.lpEntryID := nil;
lpOriginator := @lpSender;
end;
if (RecipientEmail <> '') then
begin
lpRecipient.ulRecipClass := MAPI_TO;
if (RecipientName = '') then
lpRecipient.lpszName := PChar(RecipientEMail)
else
lpRecipient.lpszName := PChar(RecipientName);
lpRecipient.lpszAddress := PChar(RecipientEmail);
lpRecipient.ulReserved := 0;
lpRecipient.ulEIDSize := 0;
lpRecipient.lpEntryID := nil;
nRecipCount := 1;
lpRecips := @lpRecipient;
end
else lpRecips := nil;
if (FileName = '') then
begin
nFileCount := 0;
lpFiles := nil;
end
else
begin
FillChar(FileAttach, SizeOf(FileAttach), 0);
FileAttach.nPosition := Cardinal($FFFFFFFF);
FileAttach.lpszPathName := PChar(FileName);
nFileCount := 1;
lpFiles := @FileAttach;
end;
end;
MAPIModule := LoadLibrary(PChar(MAPIDLL));
if MAPIModule = 0 then
Result := -1
else
try
@SM := GetProcAddress(MAPIModule, 'MAPISendMail');
if @SM <> nil then
begin
Result := SM(0, Application.Handle, Message, MAPI_DIALOG or MAPI_LOGON_UI, 0);
end
else
Result := 1;
finally
FreeLibrary(MAPIModule);
end;
if Result <> 0 then
MessageDlg('Gagal mengirim email (' + IntToStr(Result) + ').', mtError, [mbOK], 0);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMail(edtSubject.Text,
MemoMessage.Text,
'',
edtNamaPengirim.Text, edtEmailPengirim.Text,
edtNamaPenerima.Text, edtEmailPenerima.Text);
end;
end.
Thursday, August 27, 2009
Membaca Seri Prosesor Komputer
implementation
function GetCPUInfos: TStringList;
var
_eax, _ebx, _ecx, _edx: Longword;
i: Integer;
b: Byte;
s, s1, s2, s3, s_all: string;
begin
Result := TStringList.Create;
asm // asm call to the CPUID inst.
mov eax, 0 // sub. func call
db $0F, $A2 // db $0F,$A2 = CPUID instruction
mov _ebx, ebx
mov _ecx, ecx
mov _edx, edx
end;
for i := 0 to 3 do // extract vendor id
begin
b := Lo(_ebx);
s := s + chr(b);
b := Lo(_ecx);
s1:= s1 + chr(b);
b := Lo(_edx);
s2:= s2 + chr(b);
_ebx := _ebx shr 8;
_ecx := _ecx shr 8;
_edx := _edx shr 8;
end;
Result.Add('CPU' + '');
Result.Add(' - ' + 'Vendor ID: ' + s + s2 + s1);
asm
mov eax, 1
db $0F, $A2
mov _eax, eax
mov _ebx, ebx
mov _ecx, ecx
mov _edx, edx
end;
b := Lo(_eax) and 15;
Result.Add(' - ' + 'Stepping ID: ' + IntToStr(b));
b := Lo(_eax) shr 4;
Result.Add(' - ' + 'Model Number: ' + IntToHex(b, 1));
b := Hi(_eax) and 15;
Result.Add(' - ' + 'Family Code: ' + IntToStr(b));
b := Hi(_eax) shr 4;
Result.Add(' - ' + 'Processor Type: ' + IntToStr(b));
b := Lo((_eax shr 16)) and 15;
Result.Add(' - ' + 'Extended Model: ' + IntToStr(b));
b := Lo((_eax shr 20));
Result.Add(' - ' + 'Extended Family: ' + IntToStr(b));
b := Lo(_ebx);
Result.Add(' - ' + 'Brand ID: ' + IntToStr(b));
b := Hi(_ebx);
Result.Add(' - ' + 'Chunks: ' + IntToStr(b));
b := Lo(_ebx shr 16);
Result.Add(' - ' + 'Count: ' + IntToStr(b));
b := Hi(_ebx shr 16);
Result.Add(' - ' + 'APIC ID: ' + IntToStr(b));
if (_edx and $40000) = $40000 then // is serial number enabled?
Result.Add(' - ' + 'Serial Number ' + 'Enabled')
else
Result.Add(' - ' + 'Serial Number ' + 'Disabled');
s := IntToHex(_eax, 8);
asm // determine the serial number
mov eax, 3
db $0F, $A2
mov _ecx, ecx
mov _edx, edx
end;
s1 := IntToHex(_edx, 8);
s2 := IntToHex(_ecx, 8);
Insert('-', s, 5);
Insert('-', s1, 5);
Insert('-', s2, 5);
Result.Add(' - ' + 'Serial Number: ' + s + '-' + s1 + '-' + s2);
asm
mov eax, 1
db $0F, $A2
mov _edx, edx
end;
if (_edx and $800000) = $800000 then
Result.Add('MMX ' + 'Supported')
else
Result.Add('MMX ' + 'Not Supported');
if (_edx and $01000000) = $01000000 then
Result.Add('FXSAVE & FXRSTOR Instructions ' + 'Supported')
else
Result.Add('FXSAVE & FXRSTOR Instructions Not ' + 'Supported');
if (_edx and $02000000) = $02000000 then
Result.Add('SSE ' + 'Supported')
else
Result.Add('SSE ' + 'Not Supported');
if (_edx and $04000000) = $04000000 then
Result.Add('SSE2 ' + 'Supported')
else
Result.Add('SSE2 ' + 'Not Supported');
asm // execute the extended CPUID inst.
mov eax, $80000000 // sub. func call
db $0F, $A2
mov _eax, eax
end;
if _eax > $80000000 then // any other sub. funct avail. ?
begin
Result.Add('Extended CPUID: ' + 'Supported');
Result.Add(' - Largest Function Supported: ' + IntToStr(_eax - $80000000));
asm // get brand ID
mov eax, $80000002
db $0F
db $A2
mov _eax, eax
mov _ebx, ebx
mov _ecx, ecx
mov _edx, edx
end;
s := '';
s1 := '';
s2 := '';
s3 := '';
for i := 0 to 3 do
begin
b := Lo(_eax);
s3:= s3 + chr(b);
b := Lo(_ebx);
s := s + chr(b);
b := Lo(_ecx);
s1 := s1 + chr(b);
b := Lo(_edx);
s2 := s2 + chr(b);
eax := _eax shr 8;
_ebx := _ebx shr 8;
_ecx := _ecx shr 8;
_edx := _edx shr 8;
end;
s_all := s3 + s + s1 + s2;
asm
mov eax, $80000003
db $0F
db $A2
mov _eax, eax
mov _ebx, ebx
mov _ecx, ecx
mov _edx, edx
end;
s := '';
s1 := '';
s2 := '';
s3 := '';
for i := 0 to 3 do
begin
b := Lo(_eax);
s3 := s3 + chr(b);
b := Lo(_ebx);
s := s + chr(b);
b := Lo(_ecx);
s1 := s1 + chr(b);
b := Lo(_edx);
s2 := s2 + chr(b);
_eax := _eax shr 8;
_ebx := _ebx shr 8;
_ecx := _ecx shr 8;
_edx := _edx shr 8;
end;
s_all := s_all + s3 + s + s1 + s2;
asm
mov eax, $80000004
db $0F
db $A2
mov _eax, eax
mov _ebx, ebx
mov _ecx, ecx
mov _edx, edx
end;
s := '';
s1 := '';
s2 := '';
s3 := '';
for i := 0 to 3 do
begin
b := Lo(_eax);
s3 := s3 + chr(b);
b := Lo(_ebx);
s := s + chr(b);
b := Lo(_ecx);
s1 := s1 + chr(b);
b := Lo(_edx);
s2 := s2 + chr(b);
_eax := _eax shr 8;
_ebx := _ebx shr 8;
_ecx := _ecx shr 8;
_edx := _edx shr 8;
end;
Result.Add('Brand String: ' + '');
if s2[Length(s2)] = #0 then setlength(s2, Length(s2) - 1);
Result.Add('' + ' - ' + s_all + s3 + s + s1 + s2);
end
else
Result.Add(' - Extended CPUID ' + 'Not Supported.');
end;
Sunday, August 2, 2009
Sample skin application with source code ( Delphi )
Setelah utak-atik dengan graphics programming, dan berkali-kali try and error, akhirnya jadilah skin yang sederhana tetapi tetap menarik ( menurut saya pribadi… ). Selain itu dengan hanya menambahkan file-file bitmap yang total berukuran hanya sekitar 4 KB saja, bisa dihasilkan sekitar 20 macam skin, dan sangat mudah dikembangkan dan ditambah skinnya. Dengan hanya 4 KB tentu tidak banyak menambah ukuran file. Selain itu, proses perubahan skin relatif cepat dan tidak banyak memakan memory komputer, serta jalannya program juga cepat. Berikut sekilas contohnya :
Bagi anda yang penasaran dan ingin mencoba / mengembangkan sendiri, langsung download sample aplikasi, source code dan exe-nya disini (~59 KB). Sample source code dalam Delphi, diperlukan komponen KOL n MCK yang bisa di download disini. Ada pertanyaan, masukan dan tanggapan silahkan langsung email saja.