procedure GetFilenames(Path: string; Dest: TStrings);
var
SR: TSearchRec;
begin
if FindFirst(Path+'*.*', faAnyFile, SR) = 0 then
repeat
Dest.Add(SR.Name);
until FindNext(SR) <> 0;
FindClose(SR);
end;
Monday, December 12, 2011
How to Get list files from a directory in delphi
This procedure below will list all files in a directory and add it to stringlist. Here is the function :
Sunday, December 11, 2011
How to replace string in delphi
To replace string in delphi, we can use 'StringReplace' function. The pattern is
function StringReplace ( const SourceString, OldPattern, NewPattern : string; Flags : TReplaceFlags ) : string;
It replaces the first or all occurences of a substring 'OldPattern' in 'SourceString' with 'NewPattern' according to 'Flags' settings.
There are two Flags can be applied. It may be none, one, or both of these values:
rfReplaceAll : Change all occurrences
rfIgnoreCase : Ignore case when searching
Below is the example code:var
before, after : string;
begin
// Try to replace all occurrences of a or A to THE
before := 'It is a kind of fruit';
after := StringReplace(before, ' a ', ' THE ',
[rfReplaceAll, rfIgnoreCase]);
ShowMessage('Before = '+before);
ShowMessage('After = '+after);
end;
It will output this alert Before = It is a kind of fruit After = It is THE kind of fruit
Saturday, December 10, 2011
How to create trigger on mssql
In mssql we can create a trigger to get the orginal values in a separate table with the same structure to track changes on original table. It can be done using both trigger after insert, after update or after delete.
Below is scripts to create trigger in mssql :
Trigger insert
Replace tables and fields name with your own
employee is the original table, while employee_log is table to save log history of original table
Below is scripts to create trigger in mssql :
Trigger insert
CREATE TRIGGER employee_aft_ins ON employee AFTER INSERT AS INSERT INTO employee_log SELECT ID,FirstName,LastName FROM INSERTEDTrigger Update
CREATE TRIGGER employee_aft_upd ON employee AFTER UPDATE AS INSERT INTO employee_log SELECT ID,FirstName,LastName FROM DELETEDTrigger Delete
CREATE TRIGGER employee_aft_del ON employee AFTER DELETE AS INSERT INTO employee_log SELECT ID,FirstName,LastName FROM DELETEDNotes
Replace tables and fields name with your own
employee is the original table, while employee_log is table to save log history of original table
Subscribe to:
Posts (Atom)

