Gallery
Software
Music
Programming
Archive
Wednesday, Apr 24 Week 17

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

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('http://www.mortenbs.com/delphi-programming/') 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: 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;

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;

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: 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: 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

A byte is a number in the range from 0 to 255 (256 possible values). A byte is a number in the range from 0 to 255 (256 possible values). This is an unsigned number because all possible values are positive. A signed byte is a number in the range is -128 to 127 (256 possible values). With signed numbers the first bit is reserved for the /- sign. Now the highest value of a signed byte is 127, so 127 1 = -128. For a single bit there is two possible values: 0 and 1. With two bits the first bit can again be 0

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: Find aspect from width and height. function findAspect(w,h:word;d:byte=4):string; var i,c:longWord; begin if (w>=d) and (h>=d) and (w mod d=0) and (h mod d=0) then begin if w1) and (h div i>1) then begin w:=w div i; h:=h div i; if (w=2) and (h=2) then begin w:=1;h:=1 end; break; end; result:=intToStr(w) ':' intToStr(h) end else result:='0:0' end; s:=findAspect(640,480);

Delphi: Safe destruction of objects, threads and memory. Safe means checking that reference is not nil,- also clearing reference before destroying objects. Try..except used to avoid visual exception. Based on FreeAndNil procedure from SysUtils unit. Examples for objects, threads and allocated memory (pointers). procedure safeDispose(var p); procedure safeFree(var obj); procedure safeTerminate(var thrd); implementation procedure safeDispose(var p); var q:pointer;//clear reference before dispose data begin

Delphi: Map numbers based on range. Remap integer or floating point number between two ranges. Supports negative numbers, and result is bound to the destination range. function map(f,minA,maxA,minB,maxB:double):double; begin if minB>maxB then begin //negative numbers: if maxA=minA then result:=maxB else result:=(f-maxA)*(minB-maxB)/(minA-maxA) maxB; if resultminB then result:=minB; end else begin if maxA=minA then result:=minB else result:=(f-minA)*(maxB-minB)/(maxA-minA) minB; if resultmaxB

Delphi: Run a program or web-link using ShellExecute API-command. Run a program or web-link using ShellExecute api command. uses shellApi; function launch(pFileName:pAnsiChar;pParams:pAnsiChar=nil):boolean; const sz=sizeOf(TShellExecuteInfoA); var si:TShellExecuteInfoA; begin pFill(@si,sz); si.cbSize := sz; si.fMask := SEE_MASK_NOCLOSEPROCESS; si.wnd := windows.getDesktopWindow; si.lpFile := pFileName; si.lpParameters := pParams; si.lpDirectory := nil; si.nShow

Get size of large files as a 64-Bit integer (also on Delphi 32-Bit).... Get size of large files as a 64-Bit integer (also on Delphi 32-Bit)... function getFileSizeA(pFileName:pAnsiChar):int64; var h:THandle;d:TWin32FindDataA;n:TULargeInteger; begin h := windows.findFirstFileA(pFileName,d); if h=INVALID_HANDLE_VALUE then begin result:=0;exit end; n.lowPart := d.nFileSizeLow; n.highPart := d.nFileSizeHigh; result := n.quadPart; windows.findClose(h); end;

Pages about file formats and how to read/write files in Delphi. Various file headers and structures with examples.. Pages about file formats and how to read/write files in Delphi. Various file headers and structures with examples

Showing no. 21 to 40 of 49 items PreviousNext