Archive for the Delphi Category

Delphi Prism 2010 Does Not Seem To Use Subdirectories

Friday, March 5th, 2010

When working on an ASP.NET website, I find it a lot easier if you put related sections in seperate subdirectories.  For example:

CSS and Javascript can be put in a directory with caching in order to speed up the page loads

Pages that are only available to certain roles (i.e. “Admin”) can be put in a seperate directory and then you set the web.config so that only that role can access the directory.  This helps to make it really clear who the page is ment for.

While attempting to port a site from Delphi RAD 2007 to Delphi Prism 2010, I was amazed that it would not let me do this.  I even opened a site in Visual Web Developer 2008 (the Microsoft compeditor that Prism basically uses as the IDE) to check if it was a Microsoft issue.  Not only did the Microsoft Web Developer 2008 allow it, but when I went to create a code file, it suggested putting it into app_code and offered to move it there for me (but did not force me to if I didn’t want to).

In comparison, in Delphi Prism 2010, I opened {project}\css\proj.css.  Instead of allowing me to use the file where it was, Prism created a brand new file {project}\proj.css and added that to the project.  To add to the confusion, it left the old file {project}\css\proj.css.  Now I have two copies of proj.css.  I tried it with several different files and kept having this issue.

Not only is this annoying, I find that this really makes a larger site a lot harder to maintain.

Tags: , ,

Accessing Firebird from Delphi Prism 2010.

Tuesday, March 2nd, 2010

Here is a quick routine to read values from a Firebird Database into Delphi Prism.

uses FirebirdSql.Data.FirebirdClient;

method  RunSqlCmd(sqlCmd: string; resultName: string; var FieldVar: array of string; FieldName: array of string): string;
var
conStr:     string;
count:      integer;
i,j:        Integer;
colName:    string;
val:        string;
dataType:   System.Type;
dataTypeStr: String;
fbConn:     FbConnection;
fbTran:     FbTransaction;
fbReader:   FBDataReader;
fbCmd:      FbCommand;
begin
count:=WebConfigurationManager.ConnectionStrings.Count;
if(count>0)then
begin
conStr := WebConfigurationManager.ConnectionStrings['RMU'].ConnectionString;
end;
fbConn := new FbConnection(conStr);
fbConn.Open;
fbTran := fbConn.BeginTransaction();
fbCmd := new FbCommand(sqlCmd, FbConn, fbTran);
fbReader := fbCmd.ExecuteReader();
if (fbReader.Read()) then
try
for i := 0 to fbReader.VisibleFieldCount – 1 do
begin
colName := fbReader.GetName(i).ToUpper; //PRISM  GetDataTypeName  ValueType[i].Name.ToUpper();
dataTypeStr := fbReader.GetDataTypeName(i);
dataType := fbReader.GetFieldType(i);
try
if (dataType = typeof(String) ) then
val := fbReader.GetString(i).ToString
else
if (dataType = typeof(Int16)) then
val := fbReader.GetInt16(i).ToString
else
if (dataType = typeof(Int32)) then
val := fbReader.GetInt32(i).ToString
else
if (dataType = typeof(Double)) then
val := fbReader.GetDouble(i).ToString
else
if (dataType = typeof(DateTime)) then
val := fbReader.GetDateTime(i).ToString
else
val := ”;
except;
val := ”;
end;
if ((colName = resultName.ToUpper()) and (resultName <> ”)) then
result := val
else
begin
for j := Low(FieldName) to High(FieldName) do
begin
if ((colName = FieldName[j].ToUpper()) and (FieldName[j] <> ”)) then
begin
FieldVar[j] := val;
break;
end;
end;
end;
end;
except
end;
fbReader.Close;
FbConn.Close;
end;
To call it, you have a function like:
method RunSqlSelect(someParam: string);
var
custId:          string;
usrFullName:     string;
usrAccessLevel:  string;
userActive:      string;
sqlStr:          string;
results:         stringArray;
recMask: integer;
bondMask: integer;
testMask: integer;
allMask:         integer;
begin
results := new stringArray(19);
sqlStr := ‘SELECT USR_CUST_ID, USR_ID,C_TEMP_DISPLAY,USR_FIRST_NAME,USR_LAST_NAME’ +
‘  from GET_USER_INFO_R02 (”’ + userName + ”’) ‘;
RunSqlCmd(sqlStr, ”, results,
['USR_CUST_ID', 'USR_ID', 'C_TEMP_DISPLAY', 'USR_FIRST_NAME', 'USR_LAST_NAME',
'C_NAME', 'USR_RECTIFIER_PG_MASK', 'USR_BOND_PG_MASK', 'USR_TEST_PG_MASK',
'USR_ALL_PG_MASK', 'USR_ACTIVE', 'USR_PASSWORD_OK', 'USR_SHARED_MASK', 'EMAIL',
'TZ_OLSON_NAME', 'USR_REPORTS_IN_UTC', 'TZ_SHORT_DESC', 'RPT_TZ_OLSON_NAME',
'RPT_TZ_NAME_FULL']);
usrFullName := results[3] + ‘ ‘ + results[4];
custId := results[0];
//blaaa, blaa, blaaa…
end;

Tags: , , ,