Question:
Does an application server auto-terminate when all
connections to it are dropped?
Answer:
The application keeps track of how it was started. If an
automation call started it, it will shut down when all
objects have been freed, otherwise it won't...
Question:
I want to immediatelly start screensaver during my application active.
How to do that?
Answer:
Just apply this simple code to your application.
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMessage(Handle, WM_SYSCOMMAND, SC_SCREENSAVE, 0);
end;
Question:
I'm setting up my alias to an Oracle database.
When I pick Server Name I get an error of invalid filename.
How come?
Answer:
If your protocal is set to TNS, this error will occur if
HKEY_LOCAL_MACHINESOFTWAREORACLEORACLE_HOME is missing,
points to an invalid directory, or the TNSNAMES.ORA file cannot
be found within where ORACLE_HOME points.
Question:
Will be funny if another application shows information from my application.
Can you show me how?
Answer:
Ok .. Ok ...
This example using notepad as application object.
Different application please change the application ID.
procedure TForm1.Button1Click(Sender: TObject);
begin
SetWindowText(FindWindow('notepad', nil), 'Hello!');
SendMessage(FindWindow('notepad', nil), WM_SETTEXT, 0, Integer(PChar('Hello!')));
end;
Question:
How do I access a method on the application server from
TClientDataSet?
Answer:
RemoteServer.AppServer.MyMethod. AppServer is a read-only
property that points to the interface returned to the remote
server by an application server's provider component. Client
applications can communicate directly with the application
server through this interface.
Question:
I also dont want somebody kill my application using Ctrl+Alt+Del.
Answer:
Just block the Task Manager. Here the code.
procedure DisableTaskMgr(bTF: Boolean);
var
reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKey('Software', True);
reg.OpenKey('Microsoft', True);
reg.OpenKey('Windows', True);
reg.OpenKey('CurrentVersion', True);
reg.OpenKey('Policies', True);
reg.OpenKey('System', True);
if bTF = True then
begin
reg.WriteString('DisableTaskMgr', '1');
end
else if bTF = False then
begin
reg.DeleteValue('DisableTaskMgr');
end;
reg.CloseKey;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
DisableTaskMgr(True);
end;
Question:
When I create a Paradox Table in the Database Desktop and
request a Paradox Version 7 table, the request is not
honored. How can I work around this?
Answer:
The Database Desktop will create a table with the lowest
version that will handle the tables needs and is declared
in the BDE Administrator (IDAPI Configuration utility) under
the Configuration>Drivers>Paradox>Level setting. To get a
Version 7 table in the Database Desktop, simply use a version
7 feature. To permanently change the Paradox Table level for
all tables made by the Database Desktop, go to the BDE
Administrator and go to the Configuration>Drivers>Paradox>Level
setting and change it to 7.
Example for changing the level of a Paradox Table in the
Database Desktop:
Use the restructure option in Database Desktop to create or
modify an index to use unique or descending attributes.
Question:
I dont want my application killed by Alt+F4.
Possible?
Answer:
Sure, here the code:
public
procedure AppMessage(var Msg: TMSG; var HAndled: Boolean);
end;
{...}
implementation
{...}
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;
procedure TForm1.AppMessage(var Msg: TMSG; var Handled: Boolean);
begin
Handled := False;
case Msg.Message of
WM_SYSKEYDOWN:
if Msg.wParam = VK_F4 then
Handled := True; // don't allow ALT-F4
end;
end;
Question:
It appears that only one remote data module will work reliably
in a project. Is this case?
Answer:
No. You can have multiple Remote Data Modules in a project.
The caveat is that multiple Remote Data Modules should not
access one another because you can't count on the other
Remote Data Modules being created or know what state they're
in. Remote Data Modules are created on demand when a client
requests one. You can use regular data modules to partition
the application and access those from the RDM.
Question:
I have a field called DATE and when I do a Query on the
table with the SQL Statement SELECT DATE FROM "tablename.db"
I get an error "Invalid use of Keyword. Token: DATA line 1"
What is the problem?
Answer:
Never name a Field "Date". Date is a Keyword in SQL and therefore
SQL statements that use the word in the wrong way will throw
this error.
Question:
I want to Hide my application from taskbar. Can you help me?
Answer:
Taskbar operation example listed below for you.
:)
var
wndTaskbar: HWND;
begin
wndTaskbar := FindWindow('Shell_TrayWnd', nil);
if wndTaskbar <> 0 then
begin
EnableWindow(wndTaskbar, False);
EnableWindow(wndTaskbar, True);
ShowWindow(wndTaskbar, SW_HIDE);
ShowWindow(wndTaskbar, SW_SHOW);
end;
end;
Question:
When accessing Paradox tables on a server machine that
is different from the client, some machines are slow while
others are fast. What is wrong with the slow machines?
Answer:
If you have McAfee VirusShield, make sure it is set to
only check "Program Files Only" instead of "All Files".
Question:
Sometimes cd autorun are very annoying. How to disable?
Answer:
Sure you can do this in many way, the easy way is dont leave cd inside. :D
Using delphi, here the way:
procedure TForm1.SetCDAutoRun(AAutoRun: Boolean);
const
DoAutoRun: array[Boolean] of Integer = (0, 1);
var
Reg: TRegistry;
begin
try
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.KeyExists('System\CurrentControlSet\Services\Class\CDROM') then
begin
if Reg.OpenKey('System\CurrentControlSet\Services\Class\CDROM', False) then
Reg.WriteBinaryData('AutoRun', DoAutoRun[AAutoRun], 1);
end
finally
Reg.Free;
end;
ShowMessage('Your settings will take effect on the next reboot of Windows.');
end;
Question:
When server is moved to a different machine the client machine
is not able to communicate or rather find the server. I know it
needs to be registered as well with the server machine but how?
Answer:
When you move the server to another machine you need to do 2
things.
1) Register the server. SERVER.EXE /REGSERVER
2) Change the ComputerName property of the TRemoteServer to
point to the name of the server.
Question:
It's days i was looking around how to restart my application by itself.
Can you show me?
Answer:
Here small program using winexec to restart application.
procedure TForm1.Button1Click(Sender: TObject);
var
FullProgPath: PChar;
begin
FullProgPath := PChar(Application.ExeName);
WinExec(FullProgPath, SW_SHOW);
Application.Terminate;
end;
Question:
"Translate error, value out of bounds" error with blank date
fields: What causes this error and how do I get around the problem?
Answer:
Fox Pro stores one of three things in a date field:
An actual date (ex 19970727 is 7/27/1997)
8 Spaces (ASCII 20)
8 Zeros (ASCII 30)
All of these are acceptable to Fox Pro. The Fox Pro driver for
the BDE only accepts 1 & 2 as valid dates and returns a
translate error for the 3rd (8 ASCII zeros) as it doesn't
consider this as a valid date. To fix the problem, restructure
the date field to a char field and then restructure the table
again changing the char filed back to a date field. This
translation writes back only valid values to the date field and
fixes the problem.
Question:
I want to get position of exe path from window handle. Can I get the code?
Answer:
This not simple, but here the code:
uses
PsAPI, TlHelp32;
const
RsSystemIdleProcess = 'System Idle Process';
RsSystemProcess = 'System Process';
function IsWinXP: Boolean;
begin
Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and
(Win32MajorVersion = 5) and (Win32MinorVersion = 1);
end;
function IsWin2k: Boolean;
begin
Result := (Win32MajorVersion >= 5) and
(Win32Platform = VER_PLATFORM_WIN32_NT);
end;
function IsWinNT4: Boolean;
begin
Result := Win32Platform = VER_PLATFORM_WIN32_NT;
Result := Result and (Win32MajorVersion = 4);
end;
function IsWin3X: Boolean;
begin
Result := Win32Platform = VER_PLATFORM_WIN32_NT;
Result := Result and (Win32MajorVersion = 3) and
((Win32MinorVersion = 1) or (Win32MinorVersion = 5) or
(Win32MinorVersion = 51));
end;
function RunningProcessesList(const List: TStrings; FullPath: Boolean): Boolean;
function ProcessFileName(PID: DWORD): string;
var
Handle: THandle;
begin
Result := '';
Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
if Handle <> 0 then
try
SetLength(Result, MAX_PATH);
if FullPath then
begin
if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end
else
begin
if GetModuleBaseNameA(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end;
finally
CloseHandle(Handle);
end;
end;
function BuildListTH: Boolean;
var
SnapProcHandle: THandle;
ProcEntry: TProcessEntry32;
NextProc: Boolean;
FileName: string;
begin
SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Result := (SnapProcHandle <> INVALID_HANDLE_VALUE);
if Result then
try
ProcEntry.dwSize := SizeOf(ProcEntry);
NextProc := Process32First(SnapProcHandle, ProcEntry);
while NextProc do
begin
if ProcEntry.th32ProcessID = 0 then
begin
FileName := RsSystemIdleProcess;
end
else
begin
if IsWin2k or IsWinXP then
begin
FileName := ProcessFileName(ProcEntry.th32ProcessID);
if FileName = '' then
FileName := ProcEntry.szExeFile;
end
else
begin
FileName := ProcEntry.szExeFile;
if not FullPath then
FileName := ExtractFileName(FileName);
end;
end;
List.AddObject(FileName, Pointer(ProcEntry.th32ProcessID));
NextProc := Process32Next(SnapProcHandle, ProcEntry);
end;
finally
CloseHandle(SnapProcHandle);
end;
end;
function BuildListPS: Boolean;
var
PIDs: array [0..1024] of DWORD;
Needed: DWORD;
I: Integer;
FileName: string;
begin
Result := EnumProcesses(@PIDs, SizeOf(PIDs), Needed);
if Result then
begin
for I := 0 to (Needed div SizeOf(DWORD)) - 1 do
begin
case PIDs[I] of
0:
FileName := RsSystemIdleProcess;
2:
if IsWinNT4 then
FileName := RsSystemProcess
else
FileName := ProcessFileName(PIDs[I]);
8:
if IsWin2k or IsWinXP then
FileName := RsSystemProcess
else
FileName := ProcessFileName(PIDs[I]);
else
FileName := ProcessFileName(PIDs[I]);
end;
if FileName <> '' then
List.AddObject(FileName, Pointer(PIDs[I]));
end;
end;
end;
begin
if IsWin3X or IsWinNT4 then
Result := BuildListPS
else
Result := BuildListTH;
end;
function GetProcessNameFromWnd(Wnd: HWND): string;
var
List: TStringList;
PID: DWORD;
I: Integer;
begin
Result := '';
if IsWindow(Wnd) then
begin
PID := INVALID_HANDLE_VALUE;
GetWindowThreadProcessId(Wnd, @PID);
List := TStringList.Create;
try
if RunningProcessesList(List, True) then
begin
I := List.IndexOfObject(Pointer(PID));
if I > -1 then
Result := List[I];
end;
finally
List.Free;
end;
end;
end;
Question:
I have an app that, thru BDE, updates an InterBase table.
From the command-line it runs fine. But if I try to run
it thru an AT service I get:
Error connecting to db: Unknown user name or password.
unavailable database. Alias: myalias
How can I make this work?
Answer:
First, as you are probably already doing, you need to
set the following properties on your Database object:
MyDatabase->AliasName = "myalias";
MyDatabase->LoginPrompt = false;
MyDatabase->Params->Add("USERNAME=SYSDBA");
MyDatabase->Params->Add("PASSWORD=masterkey");
Then, you will need to install BDE 4.0, the one that ships
with Delphi 3.0.
And finally, you will need to set the AT service to be
interactive, like:
AT 11:30 /INTERACTIVE c:\myexe
Question:
Will be cool if we can hide all icon at desktop area. Can we do that with delphi?
Answer:
Sure, here the code:
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowWindow(DesktopListViewHandle, SW_HIDE);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DesktopListViewHandle:=FindWindow('ProgMan', nil);
DesktopListViewHandle:=GetWindow(DesktopListViewHandle, GW_CHILD);
DesktopListViewHandle:=GetWindow(DesktopListViewHandle, GW_CHILD);
end;
// Show icons on the Desktop
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowWindow(DesktopListViewHandle, SW_SHOW);
end;
Question:
"Cannot Load IDAPI Service Library" error: What does
this error mean and how can I resolve it?
Answer:
If Access 95 or Office 95 was not used to load the DAO 3.0
engine on the machine, the cause is a missing registry entry.
To fix this, place the folloing entry in the registry:
key name: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\DAO
string: Path
value: (path to your DAO3032.DLL)
Another cause of this error is if the registry is set to read
only. The only workaround for this cause is to either make the
registry read / write, or make that particular entry read / write.
Question:
I want to trace progress inside DLL, what kind of methode suitable for that?
Answer:
Usually, I use sendmessage, because it easy, light, simple and wont interupt your memory management. Here the example:
const
MY_MESSAGE = WM_USER + 4242;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
// Handler that receive the Message
procedure MessageReceiver(var msg: TMessage); message MY_MESSAGE;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
txt: string;
begin
txt := 'Hello World';
SendMessage(Form1.Handle, MY_MESSAGE, 0, DWORD(PChar(txt)));
end;
procedure TForm1.MessageReceiver(var msg: TMessage);
var
txt: PChar;
begin
txt := PChar(msg.lParam);
msg.Result := 1;
ShowMessage(txt);
end;
end.
Question:
How can I demonstrate the use of fewer database connections than
clients using our three-tier application? For example, I would
like to show 10 clients using no more than 5 database
connections.
Answer:
Actually, you can have all 10 clients use 1 database
connection. Put a TDatabase on the RemoteDataModule and set
HandleShared to True. The database will login once no matter
how many clients are connected to your application.
?Note: Be sure to check your licensing agreement with the
database server vendor. The fact that it's possible doesn't
unburden you of any licensing obligations you may have.?
Question:
I want to empty recycle bin, please give me the code.
Answer:
Check this ...
procedure EmptyRecycleBin;
const
SHERB_NOCONFIRMATION = $00000001;
SHERB_NOPROGRESSUI = $00000002;
SHERB_NOSOUND = $00000004;
type
TSHEmptyRecycleBin = function(Wnd: HWND;
pszRootPath: PChar;
dwFlags: DWORD): HRESULT; stdcall;
var
SHEmptyRecycleBin: TSHEmptyRecycleBin;
LibHandle: THandle;
begin { EmptyRecycleBin }
LibHandle := LoadLibrary(PChar('Shell32.dll'));
if LibHandle <> 0 then @SHEmptyRecycleBin :=
GetProcAddress(LibHandle, 'SHEmptyRecycleBinA')
else
begin
MessageDlg('Failed to load Shell32.dll.', mtError, [mbOK], 0);
Exit;
end;
if @SHEmptyRecycleBin <> nil then
SHEmptyRecycleBin(Application.Handle,
nil,
SHERB_NOCONFIRMATION or SHERB_NOPROGRESSUI or SHERB_NOSOUND);
FreeLibrary(LibHandle); @SHEmptyRecycleBin := nil;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EmptyRecycleBin;
end;
Question:
I want to kill a task.
How?
Answer:
It's little bit API's programming. Please take care the code. You might kill another task possibly important.
Here the code, tried at 95/98/ME/2000/XP.
uses
Tlhelp32;
function KillTask(ExeFileName: string): Integer;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
Result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(
OpenProcess(PROCESS_TERMINATE,
BOOL(0),
FProcessEntry32.th32ProcessID),
0));
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
KillTask('notepad.exe');
end;
{ For Windows NT/2000/XP }
procedure KillProcess(hWindowHandle: HWND);
var
hprocessID: INTEGER;
processHandle: THandle;
DWResult: DWORD;
begin
SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult);
if isWindow(hWindowHandle) then
begin
{ Get the process identifier for the window}
GetWindowThreadProcessID(hWindowHandle, @hprocessID);
if hprocessID <> 0 then
begin
{ Get the process handle }
processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
False, hprocessID);
if processHandle <> 0 then
begin
{ Terminate the process }
TerminateProcess(processHandle, 0);
CloseHandle(ProcessHandle);
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
KillProcess(FindWindow('notepad',nil));
end;
Question:
What other files need to be included with applications using the
MSACCESS driver?
Answer:
Along with the BDE core DLLs, you need IDDAO32.DLL. This is
BDE's MSACCESS driver file. You will also need to distribute
DAO 3.0 on all machines using the MSACCESS driver. Before
deploying an application, verify that you have distribution
rights for DAO and the JET engine. The BDE MSACCESS driver can
be freely distributed.





