Friday, Mar 22 Week 12

Page 2 of 3  
Showing no. 21 to 40 of 49 items PreviousNext  

Delphi: Download HTML-source from internet as text. Customize the parameters for timeout and redirects. It returns the destination URL when navigating is done. uses idHttp; const INET_USERAGENT = 'Mozilla/4.0, Indy Library (Windows; en-US)'; INET_TIMEOUT_SECS = 3; INET_REDIRECT_MAX = 10; function downloadSrc(var aUrl:ansiString):ansiString; begin with tIdHttp.create(nil) do begin //Create Indy http object request.userAgent:=INET_USERAGENT; //Custom user agent string

TLedPanel component for Delphi. TLedPanel component for Delphi is simple and easy to use. A small demo project is included in the archive

Delphi: Use TLabel as link to a web site (URL). Create new label on the form, and doubleclick on it to create OnClick event. uses windows,shellApi,forms; function launchUrl(url:ansiString;h:THandle=INVALID_HANDLE_VALUE):boolean; begin if h=INVALID_HANDLE_VALUE then h:=application.handle; result:=shellExecuteA(h,'open',pAnsiChar(url),nil,nil,SW_NORMAL)>0; end; procedure TForm1.Label1Click(Sender: TObject); begin launchUrl('') end;

Delphi: IP to host name, and host name to IP. When successfully looking up DNS hostname for IP-addresses, it returns a - domain name, often with country code extension and other useful information. Automatically detecting if to lookup hostname or IP-address. By giving valid IP address syntax it will lookup hostname, and - by giving a hostname it will lookup the IP address. function dnsLookUp(p:pAnsiChar):ansiString; function validIp(p:pAnsiChar):boolean; function pCopy(p:pAnsiChar;n:longWord):ansiString;

Delphi Remove certain characters from a string. type TCharSet = set of ansiChar; //Allows multiple chars as argument in routine below const NULL = #0; function removeChars(p:pAnsiChar;ch:TCharSet):ansiString; var rP:pAnsiChar;k:longWord; begin rP:=p;k:=0; //Reset while rP^NULL do begin //Find length and count chars if rP^ in ch then inc(k); //Number of chars to remove inc(rP);

Delphi: Fast load Jpeg into Bitmap, keep quality. Specifying the maximum required size (width and height) will make it load faster. Useful for making JPEG thumbnails and so on. It uses JPEG Scale property when required maximum size is known. function loadJPEG(bmp:TBitmap;aFileName:string;rqW:word=0;rqH:word=0):boolean; var jpg:TJpegImage;w,h:word; begin jpg:=TJpegImage.Create; result:=false; with jpg do try performance:=jpBestQuality; loadFromFile(aFileName); w:=width; h:=height; if (w0) and

Delphi: Convert ANSI text to word or byte. Two examples of converting ANSI text into numbers. Using of the functions requires that the text is actually a number, and that it fits into a byte/word. The examples is faster if the length is known. function strToByte(p:pAnsiChar;n:byte):byte; begin case n of 1:result:=pByte(p)^-48; 2:result:=((pByte(p)^-48)*10) pByte(p 1)^-48; 3:result:=((pByte(p)^-48)*100) ((pByte(p 1)^-48)*10) pByte(p 2)^-48 else result:=0 end end; function

Delphi: Remove file extension from filename string. const NULL = #0; function removeFileExt(p:pAnsiChar):ansiString; var p1,p2:pAnsiChar; begin p2:=nil;p1:=p; while p^NULL do begin if p^='.' then p2:=p;inc(p) end; if p2=nil then p2:=p; setLength(result,p2-p1); p:=pAnsiChar(result); while p1p2 do begin p^:=p1^;inc(p);inc(p1) end; end; procedure TForm1.FormCreate(Sender: TObject); var s:ansiString; begin s:='C:\test.pas'; caption:=string(removeFileExt(pAnsiChar(s))); end;

Simple fader and rotary components for Delphi. Simple fader and rotary component for Delphi. unit faderRotary; interface uses windows,classes,controls,graphics,messages; {$R faderRotary.dcr} type TSimpleEvent = procedure of object;//no arguments TStateEvent = procedure(sender:TObject;user:boolean) of object; TVsEvent = procedure(e:byte;x,y:longInt;key:byte;sender:TObject) of object; //--------------------------|---------------------|-----------------------|-------------------------0 then

Delphi: Convert between IPv4 string and 32-Bit unsigned number. The maximum length of an IPv4 address string is 15 1 (NULL) chars (16 bytes) and the 32-Bit number is only 4 bytes. Also possibility of comparing if one IP address if above/below an other. const NULL = #0; //Blank char function strToByte(p:pAnsiChar;n:byte):byte; begin case n of 1:result:=pByte(p)?-48; 2:result:=((pByte(p)?-48)*10) pByte(p 1)?-48; 3:result:=((pByte(p)?-48)*100) ((pByte(p 1)?-48)*10) pByte(p 2)?-48; else result:=0 end;

Delphi: check if a string only contains numbers. const NULL = #0; //Blank char TNumbs = ['0'..'9']; //Set of numerical chars function isNumeric(p:pAnsiChar):boolean; var n:longWord; begin result:=false;if p=nil then exit; //Check input if p^='-' then inc(p); //Ignore minus if p^=NULL then exit; //Deny empty input while p^NULL do //Loop chars if p^ in TNumbs then inc(p) else exit;

Delphi: Fast copy characters from a string pointer. function pCopy(p:pAnsiChar;n:longWord):ansiString; var rP:pAnsiChar; begin setLength(result,n); rP:=pAnsiChar(result); while n0 do begin rP^:=p^; inc(rP); inc(p); dec(n); end; end; procedure TForm1.FormCreate(Sender: TObject); var s:ansiString; begin s:='1234567890'; caption:=pCopy(pAnsiChar(s),4); end;

Delphi: Get filename and arguments from a LNK-shortcut file. uses windows,shellApi,comObj,shlObj,activeX; type TPathStr = array[byte] of ansiChar; function getLnkShortcut(aFileName:string;out aFile,aArgu:string):boolean; var s :TPathStr; wfs :TWin32FindDataA; psl :iShellLinkA; ppf :iPersistFile; begin result:=false; aFile:=''; aArgu:=''; if coCreateInstance(CLSID_SHELLLINK,nil,CLSCTX_INPROC_SERVER,iShellLinkA,psl)=NOERROR then if

Delphi: Extract GIF frames to folder (TGifImage 2.2). Extract each frame from a GIF animation to a folder. The separate images is drawn on a bitmap, while it is saved as files in the folder. uses sysUtils, gifImage, graphics, classes, ... //.. function gifFramesToFolder(gif:TGifImage;aDestDir:string):boolean;overload; var i:longInt;bmp:TBitmap;r:TRect;gc:TGifGraphicControlExtension;s:string; begin result:=false; bmp:=TBitmap.create; with gif do try bmp.pixelFormat:=pf24bit; bmp.width:=width;

Delphi: Check if a string contains a valid IP-address. Fast routine to verify af a string contains an IP-address (IPv4) of valid syntax. function validIp(p:pAnsiChar):boolean; function pCopy(p:pAnsiChar;n:longWord):ansiString; function pLen(p:pAnsiChar):longWord; implementation {$R *.dfm} const NULL = #0; //Blank char NONE = $00; //Blank number function validIp(p:pAnsiChar):boolean; var lP:pAnsiChar;i,e:integer;b:byte; begin result:=false; b:=NONE; lP:=p; while p^NULL do

Delphi: Prime numbers (32-Bit). function isPrimeNumber(n:longWord):boolean; var i,k:longWord; begin k:=0; for i:=1 to n do begin if n mod i=0 then inc(k); if k>2 then break; end; result:=k=2; end;

Delphi: Remove HTML-tags from text. const NULL = #0; function pPos(p:pAnsiChar;ch:char):longWord; var q:pAnsiChar; begin result:=0; q:=p; while p^NULL do if p^=ch then begin result:=p-q 1;exit end else inc(p); end; function removeHtml(p:pAnsiChar;aLen:longWord):ansiString; const ch=['0'..'9','a'..'z','A'..'Z']; var eP,rP,p1:pAnsiChar;v,n:longWord; begin setLength(result,aLen);if aLen=0 then exit; rP:=pAnsiChar(result); p1:=rP; n:=aLen;

Delphi: Find random number, float, boolean, text or color. function maybe(aRandomize:boolean=false):boolean; //Random boolean begin if aRandomize then randomize; result:=random(2)=0; end; function randomRange(min,max:longInt;aRandomize:boolean=false):longInt; begin if aRandomize then randomize; result:=random(max-(min-1)) min; end; function randomFloat(aMin,aMax:double):double; begin result:=randomRange(trunc(aMin*1000),trunc(aMax*1000))/1000 //three decimals end; function

Delphi: Get lower case file extension from a string. const NULL = #0; function lcFileExt(p:pAnsiChar;aWantDot:boolean=false):ansiString; var dP:pAnsiChar; begin dP:=nil; while p^NULL do begin if p^='.' then dP:=p;inc(p) end; if dP=nil then begin result:='';exit end; if not aWantDot then inc(dP); setLength(result,p-dP);p:=pAnsiChar(result); while dP^NULL do begin p^:=dP^;if p^ in ['A'..'Z'] then inc(p^,$20); inc(p);inc(dP) end end; procedure

Delphi: Count characters from a string. The routine can be used to count dots in domain names and many other things. Because of the use of pointers the routine is fast. type TCharSet = set of ansiChar; //Allows multiple chars as argument in routine below const NULL = #0; function pCount(p:pAnsiChar;ch:TCharSet):longWord; begin result:=0; if pnil then while p^NULL do begin if p^ in ch then inc(result); inc(p) end end; procedure TForm1.FormCreate(Sender: TObject); var n:longWord;s:ansiString; begin

Showing no. 21 to 40 of 49 items PreviousNext