Tuesday, April 17, 2012

Freeing Delphi Dynamic Arrays

This post is about freeing dynamic arrays in, Delphi.

In, Delphi, as in others, dynamic arrays useful in many instances. Here is a good link on a basic understanding
http://delphi.about.com/od/beginners/a/arrays.htm This is not what this post is about.

Let's declare a dynamic array and we will use the same variables as the link above so to make it easier to understand


var
  Students : array of string; 
  nCounter: integer;
begin
  // set the length to something
  SetLength(Students,5); // this will hold six students
  // loop through and load the array with some data
  for nCounter := Low(Students) to High(Students) do
  begin
    Students[nCounter] := 'My student #: ' + inttostr(nCounter);
  end;

  // do something
  // way one to free array
  Students := nil;
  // way two to free array
  SetLength(Students,0);
  // way three to free array
  Finalize(Students);
end;


There you go!

Wednesday, April 4, 2012

Enter ASCII Characters

Several ways to accomplish entering ® or © into text. In Word® you can select it from the fonts. You can also use the Character Map in Windows and find your character and hit copy.

The cool way is to hold down the ALT key and then, using the keypad, type the appropriate ASCII number. For example:
® = ALT + 0174
© = ALT + 0169

You can use this for any of the ASCII characters.

Happy typing.

Tuesday, November 29, 2011

TSQL Delete All Data

So you want to delete all the contents of the tables in your MS SQL database. You could drop and create the database. You could also drop and create the tables within the database. Then, you could iterate through all the tables in the INFORMATION_SCHEMA and delete all the rows with a TSQL script.

Here is the script I used:

USE [YourDatabase];
GO
SET NOCOUNT ON;
DECLARE @MyTableName varchar(100);

DECLARE MyCursor CURSOR
  FOR SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
  WHERE TABLE_CATALOG = 'YourDatabase' AND TABLE_SCHEMA = 'dbo';
OPEN MyCursor;
FETCH NEXT FROM MyCursor INTO @MyTableName;

WHILE @@FETCH_STATUS = 0
BEGIN
  EXEC ('DELETE FROM ' + @MyTableName);
  FETCH NEXT FROM MyCursor INTO @MyTableName;
END;
CLOSE MyCursor;
DEALLOCATE MyCursor;

Tuesday, August 23, 2011

SQL Server Full-Text Searching

Sometimes, a blog will contain information you wrote on a topic. Other times, a blog will be a posting about what others have already put together.

This post is the latter.

Recently, the opportunity arose to research how to search binary data in a database. The constraints were the document was stored in the table and it needed to work with SQL Server or Oracle. This post will, focus mostly on SQL Server.

This article shows in great detail how to setup the full-text indexing and provides great explanation as to many of the options within the syntax.

The article uses the Adventure Works database. If you need the Adventure Works database.

Then, after this was tested out, this article was found on Google type searching within a SQL Server.

And finally, some information on Google searching.

All these links were last tested: 23 Aug 2011.

Friday, August 19, 2011

Delphi Sets

A simple example of doing enumerator sets in Delphi. There are several other examples available, I will provide links at the end of this post.

1) Declare an enumerated type:
TeDaysOfWeek = (eDoWMonday, eDoWTuesday, eDoWWednesday, eDoWThursday, eDoWFriday, eDoWSaturday, eDoWSunday);

2) Declare a set of the enumerated type:
TeDaysOfWeekSet = set of TeDaysOfWeek;

3) Declare a variable to work with the set:
var
  eDOWSetWork: TeDaysOfWeekSet ;

4) Add items to the working set. Say the application is indicating what days the doctor is available:
// sets the set to empty
eDOWSetWork := [];
// add values to the set
if (some_boolean_values) then
begin
  eDOWSetWork := eDOWSetWork + [eDoWMonday, eDoWTuesday];
end;
if (some_other_condition) then
begin
  eDOWSetWork := eDOWSetWork + [eDoWWednesday];
end;

What you are doing with the "set = set + enumerator" is adding values into the set. You could also set the set:
eDOWSetWork := [eDoWWednesday];
This would replace any values in the set with just eDoWWednesday.

This sets the set for use, now we need to use it for comparison or other behavior:
5) Implement behavior:
procedure DoSomething(p_eDOWSetWork: TeDaysOfWeekSet);
begin
  if (eDoWWednesday in p_eDOWSetWork) then
  begin
  end;
end;

Other links for sets:
http://delphi.about.com/od/beginners/a/delphi_set_type.htm
http://www.delphibasics.co.uk/Article.asp?Name=Sets
Sets in Delphi Prism: http://prismwiki.codegear.com/en/Sets


Friday, August 12, 2011

Move to Top of Page


Tap the bar at the top of the iPhone page, whatever the page to return to the top - the gray part in this image: