مجموعه Tip شماره ۳ ایران دولوپرز دات کام
گردآورى: محمد باقر معممورى
| مقایسه یک رشته با یک الگو |
|
{
Sometimes we need to know if a string matches a
pattern, which is a string with wildcards
(for example ? and *).
Usage:
if IsLike('About Delphi', 'Abo?? Delp*') then
ShowMessage('A match!');
}
uses SysUtils;
function IsLike(AString, Pattern: string): boolean;
var
i, n, n1, n2: integer;
p1, p2: pchar;
label
match, nomatch;
begin
AString := UpperCase(AString);
Pattern := UpperCase(Pattern);
n1 := Length(AString);
n2 := Length(Pattern);
if n1 < n2 then n := n1 else n := n2;
p1 := pchar(AString);
p2 := pchar(Pattern);
for i := 1 to n do begin
if p2^ = '*' then goto match;
if (p2^ <> '?') and (p2^ <> p1^) then goto nomatch;
inc(p1); inc(p2);
end;
if n1 > n2 then begin
nomatch:
Result := False;
exit;
end else if n1 < n2 then begin
for i := n1 + 1 to n2 do begin
if not (p2^ in ['*','?']) then goto nomatch;
inc(p2);
end;
end;
match:
Result
end;
|
|
| پیدا کردن Handle یک چاپگر بر اساس نام آن |
|
{
Here's how to get a Printer Handle
provided with the Printer name:
}
function PrinterHandleByName(PrinterName : string):THandle;
var
PtrName : PChar;
begin
Result:=0;
PtrName := PChar(PrinterName);
if not OpenPrinter(PtrName, Result, nil) then
RaiseLastOSError
else
begin
ClosePrinter(Result);
end
end;
|
|
| تبدیل String به Enum |
|
{
Here's how to get the value of
an enumerated type constant
given its string representation.
Suppose enum:
TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava);
}
uses TypInfo;
var
s: string;
programmer : TProgrammerType;
begin
s:='tpDelphi'; // string
programmer := TProgrammerType(GetEnumValue(
TypeInfo(TProgrammerType),s));
end;
|
|
دیدگاه خود را بیان کنید.
باید وارد سایت شده باشید برای دیدگاه دادن