[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Personal useful common routines for all

Posted on 2005-05-11
14
Medium Priority
?
236 Views
Last Modified: 2010-04-05
Hi all,

After reading so many PAQs recently, I decided to write a unit holding commonly useful delphi routines.
I already do this to some extent anyway, but I thought it would be good to get views from other experts as to what they keep in store, and what they think are their most useful routines. They could be small or large I don't mind.

I will split points to everyone who contributes a useful routine or good points to this thread.

If this question should be in another area then I apologise.
0
Comment
Question by:mikelittlewood
  • 5
  • 2
  • 2
  • +3
14 Comments
 
LVL 15

Author Comment

by:mikelittlewood
ID: 13976475
Here is one to start off with which I think I saw Voodooman write.
Obviously it only changes the cursor, but it shows that even the smallest routine can be useful.

procedure curState(bState: Boolean);
begin
  if bState then
    Screen.Cursor := crHourglass
  else
    Screen.Cursor := crDefault
end;
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 400 total points
ID: 13976504
>If this question should be in another area then I apologise.
as it is delphi, and no sub-topics established yet, so i would say this topic is ok

i will provide this small function, which helps me a lot,

//this simple function returns the first part as result,
//and shorten the given string
//for next item simple call again
//if there are no items, then the given string becomes empty
function SplitStr(Var AString : String; ADelim : String) : String;
var APos : Integer;
begin
  Result := '';
  APos := Pos(ADelim,AString);
  if APos > 0 then
  begin
    Result := Copy(AString,1,APos-1);
    AString := copy(Astring,APos+length(Adelim),MaxLongInt);
  end
  else
  begin
    Result := AString;
    AString := '';
  end;
end;

meikl ;-)
0
 
LVL 11

Assisted Solution

by:robert_marquardt
robert_marquardt earned 400 total points
ID: 13976659
How about http://jcl.sf.net ?
The Jedi Code Library is just such a set of useful functions and classes. No components contained.
The JediVCL http://jvcl.sf.net iis for the components. Currently more than 500.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 13976676
i thought there was already a tough code library, but jedi i had not in mind, as allways :-))
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 13976910
Admittedly a lot of information there robert_marquardt, and Im sure I can find some useful routines in there to use.
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 13977135
Even Borland uses the JCL in D2005 :-)
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 13977743
Understandable robert_marquardt, its a very well rounded set of routines and components.

I just thought it would be nice to find any personal routines that people have used or made which they find useful to themselves which they might like to share.
It also tends to point me in directions of ideas I wouldnt normally think of.
0
 
LVL 13

Assisted Solution

by:BlackTigerX
BlackTigerX earned 400 total points
ID: 13980194
I use this function a lot, whenever I have a Status bar on my programs, instead of hardcoding values (or constants) for the panel where I want stuff displayed

procedure SetStatusBar(var StB:TStatusBar; const Strs:array of string; const PM:Boolean=True);
var X:Byte;
begin
  for X:=Low(Strs) to High(Strs) do
    if not (Strs[X]='') then
      StB.Panels[X].Text:=Strs[X];
  if (PM) then
    Application.ProcessMessages
end;

you just call it like SetStatusBar(SomeStatusBar, ['panel1', ' ', 'panel 3']) //notice the space to leave a panel empty

and notice that it can raise an exception if you don't have enough panels and call it with more parameters, which can be easily fixed anyway

    if (X>=StB.Panels.Count) then //fix, I don't use this because I want to know if I missed adding a panel
      Exit;

    if not (Strs[X]='') then
      StB.Panels[X].Text:=Strs[X];
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13980204
I also use this all the time to setup my SQL connection strings:

//*** Returns a "SQL Ready" string, given all the parameters
function GetSQLConnStr(const UserID, Password, InitialCatalog, DataSource:string):string;

function GetSQLConnStr(const UserID, Password, InitialCatalog, DataSource:string):string;
const
  CONN_STR = 'Provider=SQLOLEDB.1;Password=%s;Persist Security Info=True;User ID=%s;Initial Catalog=%s;Data Source=%s';
begin
  Result:=Format(CONN_STR, [Password, UserID, InitialCatalog, DataSource])
end;
0
 
LVL 5

Assisted Solution

by:Voodooman
Voodooman earned 400 total points
ID: 13982224

Hi

These are my favourites -why bother writing MessaegDialogues all the time?

I just call EMessage, Imessage and AskQuestion.

I use these in VB and Delphi.

I always kill any hourglass.  The reason for this is that sometimes errors occurr whilst the hourglass is showing and it saves we putting wiat(false); in my error traps!

function askQuestion(Question:string): Boolean;


Begin

askquestion:=False;

if MessageDlg(Question, mtConfirmation, [mbYes,mbNo], 0) = mrYes then askquestion:=true


end;

Procedure EMessage(EMessage:String);

begin

Screen.Cursor:=crDefault;
 MessageDlg(Emessage, mtError, [mbOK], 0);

end;




Procedure IMessage(IMessage:string);

begin
 Screen.Cursor:=crDefault;
 MessageDlg(Imessage, mtInformation, [mbOK], 0);

end;

As far as external controls are concerned I tend only to use ones that I really, really like. Like DBISAM, flatControls, EHLib, VgControls , Animated Menus and FastReports and a few others Most of the best controls I have I paid for and everyone of them was money well spent.

Good Luck Voodooman
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 13984470
Some nice information here thanks all. Gonna keep the thread open for a little longer while others hopefully add some more.
0
 
LVL 11

Assisted Solution

by:ZhaawZ
ZhaawZ earned 400 total points
ID: 14001745
Converting integers from dec to bin, oct, hex or other (custom) system and vice versa



function convert(vFrom : cardinal; vBase : string; vChars : string = '') : string; overload;
var
  n : integer;
begin
if vBase = 'bin' then vChars := '01' else
if vBase = 'oct' then vChars := '01234567' else
if vBase = 'dec' then vChars := '0123456789' else
if vBase = 'hex' then vChars := '0123456789abcdef';
result := '';
if length(vChars) >= 2 then begin
  repeat
    result := vChars[vFrom mod length(vChars) + 1] + result;
    vFrom := vFrom div length(vChars);
  until vFrom = 0;
end;
end;

function convert(vFrom : string; vBase : string; vChars : string = '') : cardinal; overload;

  function pow (Base, Exponent: Int64) : Int64;
  begin
  result := 1;
  while Exponent > 0 do begin
    result := result * Base;
    Exponent := Exponent - 1;
  end;
  end;

var
  n1, n2 : integer;
begin
if vBase = 'bin' then vChars := '01' else
if vBase = 'oct' then vChars := '01234567' else
if vBase = 'dec' then vChars := '0123456789' else
if vBase = 'hex' then vChars := '0123456789abcdef';
result := 0;
if length(vChars) >= 2 then begin
  n1 := 0;
  n2 := length(vFrom);
  repeat
    inc(n1);
    dec(n2);
    result := result + (pos(vFrom[n1], vChars) - 1) * pow(length(vChars), n2);
  until n1 = length(vFrom);
end;
end;



convert(2534, 'bin') - from dec to bin (if first parameter is integer, then convert TO specified system)
convert('2534', 'hex') - from hex to dec (if first parameter is string, then convert FROM specified system)
convert(234, '', 'abcdefghijklmnopqrstuvz') - from dec to specified characters
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 14027055
Thanks for all your input people, was informative and also gave me some ideas of my own.
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 14027203
Hi and thanks for the points!

Interesting topic!

Great thing about  Delphi is the range of tools available, often very reasonably priced or free.

The price of tools for Visual Basic is extortion (in my opinion).  I have spent $10k on tools for VB and have nothing like the power and quality of Delphi Tools.

On the other hand I would hate to build and maintain a really bug Delphi project with 100+ forms........let's not go there!

Thanks again

Voodooman





0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 14 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question