BORLAND DELPHI

Forum diskusi pemrograman desktop lain.

Re: BORLAND DELPHI

Postby fransgenkaku » 13 Jul 2010, 11:50

dolby358 wrote:om,kalo mau liat Previous Instance gmn?


Code: Select all
  if NOT IsPrevInst then
    begin
      Application.Initialize;
      Application.CreateForm(TMainForm, MainForm);
      Application.Run;
    end
  else
    Application.Terminate;


klo pake hWnd ni ada lagi cntohnya
Code: Select all
var
  Hwnd: THandle;
begin
  Hwnd := FindWindow ('TForm1', nil);
  if Hwnd = 0 then
  begin
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end
  else
    SetForegroundWindow (Hwnd)


P.S : Lebih baik buat trit baru ja om klo ada pertanyaan koding delphi ;) ;)
Sebarkanlah ilmu yang kau miliki....!!!

Malu bertanya sesat di jalan...(salaaaah)
Malu bertanya gak akan ngerti....!!!(ini baru betul)
User avatar
fransgenkaku
Prajurit Satu
Prajurit Satu
 
Posts: 236
Joined: 12 Mar 2010, 12:36
Location: Jember
Memberi kopi: 0 cangkir
Mendapat kopi: 2 cangkir

Re: BORLAND DELPHI

Postby tatangs » 30 Jul 2010, 17:54

Tambahan untuk contoh dan fungsinya
Code: Select all
// ===================================================
// Called by your project file, prevents a 2nd
// instance of the program from executing and
// instead activates the already executing instance.
// Returns TRUE if a previous instance of the
// program is already running. Win32 ONLY
// ===================================================
function IsPrevInst: Boolean;
var
  semName,
  appClass: PChar;
  hSem    : THandle;
  hWndMe  : HWnd;
  appTitle: Array[0..MAX_PATH] of Char;
begin
  // Init
  Result := FALSE;
  GetMem(semName,15);
  GetMem(appClass,15);
  StrPCopy(semName,'SemaphoreName');
  StrPCopy(appClass,'TApplication');
  StrPCopy(appTitle,ExtractFileName(Application.Title));

  // Create a Semaphore in memory.  If this is the
  // first instance, then hSem's value should be 0.
  hSem := CreateSemaphore(nil,0,1,semName);

  // Check to see if the semaphore exists
  if (hSem <> 0) and (GetLastError() =
                      ERROR_ALREADY_EXISTS) then
    begin
      CloseHandle(hSem);

      // Get the current window's handle then change
      // its title so we can look for the other instance
      hWndMe := FindWindow(appClass,appTitle);
      SetWindowText(hWndMe,'ZZZZZZZ');

      // Search for other instance of this window then bring
      // it to the top of the Z-order stack.  We find it by
      // matching the Application Class and
      // Application Title.
      hWndMe := FindWindow(appClass,appTitle);
      if (hWndMe <> 0) then
        begin
          BringWindowToTop(hWndMe);
          ShowWindow(hWndMe,SW_SHOWNORMAL);
        end;

      Result := TRUE;
    end;

  // Destroy PChars
  FreeMem(semName,15);
  FreeMem(appClass,15);
end;

//This is a different twist on the previous example.

procedure CheckPrevInstEx(MainFormClassName,
                          MainFormCaption : String);
var
  PrevWnd: HWnd;
  Mutex  : THandle;
begin
  {$IFDEF Win32}
  Mutex := CreateMutex(NIL, False, 'InstanceMutex');
  if WaitForSingleObject(Mutex, 10000) = WAIT_TIMEOUT then
    Application.Terminate;
  {$ELSE}
  if HPrevInst = 0 then
    Application.Terminate;
  {$ENDIF}

  PrevWnd := FindWindow(PChar(MainFormClassName),
                        PChar(MainFormCaption));
  if PrevWnd <> 0 then
    PrevWnd := GetWindow(PrevWnd, GW_OWNER);
  if PrevWnd <> 0 then
    begin
      if IsIconic(PrevWnd) then
        ShowWindow(PrevWnd,SW_SHOWNORMAL)
      else
        {$IFDEF Win32}
          SetForegroundWindow(PrevWnd);
        {$ELSE}
          BringWindowToTop(PrevWnd);
        {$ENDIF}
      Application.Terminate;
    end;
  ReleaseMutex(Mutex);
  CloseHandle(Mutex);
end;

//This example uses the IsPrevInst function

uses
  Forms,
  Main in 'Main.pas' {MainForm},
  Proc in 'Proc.pas',
  //This is my global library
  UTIL32 in '..\Lib\UTIL\Util32.pas',
  LoopPnThr in '..\Packages\LoopPnThr.pas';

{$R *.RES}

begin
  if NOT IsPrevInst then
    begin
      Application.Initialize;
      Application.CreateForm(TMainForm, MainForm);
      Application.Run;
    end
  else
    Application.Terminate;
end.
    //Here's the other way...
    program RxProto;

uses
  Forms,
  Main in 'Main.pas' {MainForm},
  Proc in 'Proc.pas',
  UTIL32 in '..\Lib\UTIL\Util32.pas',
  LoopPnThr in '..\Packages\LoopPnThr.pas';

{$R *.RES}

begin
  CheckPrevInstEx('TApplication', 'My Application');
  //This code won't do anything if CheckPrevInstEx doesn't
  //pass muster
  Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.


;)
User avatar
tatangs
Prajurit Kepala
Prajurit Kepala
 
Posts: 359
Joined: 19 Mar 2010, 10:02
Location: Cimahi
Memberi kopi: 23 cangkir
Mendapat kopi: 52 cangkir

Re: BORLAND DELPHI

Postby novaedp » 21 Aug 2010, 20:29

mbahlawoe wrote:Wah... Delphi dah "masa lalu" om... Yang bikin Delphi aja dah kabur ke Microsoft dan akhirnya bikin .NET.... kita sekarang mau "kangen2"nan ma produknya :D


Tapi.... Asyik juga sih :))


di surabaya bnyk loh software house yg pake delphi sbg bahasa utamanya,
umunya pake delphi 7
just wanna code something and share it.
novaedp
Prajurit Kepala
Prajurit Kepala
 
Posts: 468
Joined: 26 Mar 2010, 18:56
Memberi kopi: 8 cangkir
Mendapat kopi: 58 cangkir

Re: BORLAND DELPHI

Postby ekaperintis » 03 Sep 2010, 23:37

Hayolah kawan-kawan yang sudah familiar dengan delphi share di sini,,, biar ane bisa belajar Lazarus :D
Image
User avatar
ekaperintis
Sersan Satu
Sersan Satu
 
Posts: 2088
Joined: 17 Mar 2010, 14:27
Location: Parungpanjang-Bogor
Memberi kopi: 82 cangkir
Mendapat kopi: 154 cangkir

Re: BORLAND DELPHI

Postby giblartar » 19 Jan 2011, 14:45

ada yang bisa bantu..

Code: Select all
procedure TForm1.dskepegStateChange(Sender: TObject);
begin
case dskepeg.State of
dsEdit: kondisi(false);
dsBrowse: kondisi(true);
dsInsert: kondisi(false);
end;
end;


procedure TForm1.btnbaruClick(Sender: TObject);
var sPesan, sCari, sPesanCari: string;
begin
sPesan:= 'Apakah yakin akan menghapus data dengan NIP : ';
sPesan:= sPesan + dmkepeg.kepeg.Fields[0].AsString + ', dan Nama : ';
sPesan:= sPesan + dmkepeg.kepeg.Fields[1].AsString + ' ?';

case TButton(Sender).Tag of
1 : dmkepeg.kepeg.Append;
2 : dmkepeg.kepeg.Edit;
3 : dmkepeg.kepeg.Cancel;
4 : dmkepeg.kepeg.post;
5 : if (MessageBox(Self.Handle,PChar(sPesan), 'Konfirmasi',MB_YESNO +
MB_ICONINFORMATION)=ID_YES) then
dmkepeg.kepeg.Delete;
6 :
begin
sCari:=InputBox('Cari NIP','Input NIP :','NIP');
if (sCari = '') then
MessageBox(Self.Handle,'Input kosong tidak diizinkan !!!', 'Perhatian',
MB_OK + MB_ICONINFORMATION)
else if not dmkepeg.kepeg.findKey([sCari]) then
begin
sPesanCari:= 'NIP : ' + sCari + ' tidak ada !!!';
MessageBox(Self.Handle,PChar(sPesanCari), 'Informasi',MB_OK + MB_ICONINFORMATION)
end;
end;
end;


pesan eror ny gni oom :


[Error] app_kepeg.pas(150): Undeclared identifier: 'findKey'
[Error] app_kepeg.pas(150): Ordinal type required
[Fatal Error] kepegbpr.dpr(6): Could not compile used unit 'app_kepeg.pas'

ap maksudnya y?..
giblartar
Prajurit Dua
Prajurit Dua
 
Posts: 2
Joined: 18 Jan 2011, 19:40
Memberi kopi: 0 cangkir
Mendapat kopi: 0 cangkir

Previous

Return to Other Desktop Development

Who is online

Users browsing this forum: No registered users and 1 guest