Showing posts with label delphi code. Show all posts
Showing posts with label delphi code. Show all posts

Saturday, August 16, 2008

Filter bad language with Delphi / Pascal...

This has been adapted from a ISAPI web application. The first step is to fill a TStringList with a list of bad words, or even characters that you don't want to save into your database.

I've call my StringList BWSL. After initializing the StringList, and adding the words, loop through and see if any of the words you've added are present.

If they are, redirect, or use other handling depending on the type of application you're writing. My form element on the calling web page is in the variable "Tag"

EXAMPLE:


---------------------------------------------------------------------------------
for I:=0 to BWSL.Count-1 do
if pos (BWSL.Strings[I], LowerCase(tag)) > 0 then begin
Response.SendRedirect(Request.ScriptName+'/BadRequest?Bid=6&Extra=The_Word,_Character,_or_Phrase,_' + BWSL.Strings[I] +'_is_Prohibited.');
Exit;
end;
---------------------------------------------------------------------------------

Thursday, August 14, 2008

Use Crystal Reports in Delphi ISAPI Web Application

Well obviously, you may have tried to use the VCL component, and cashed and burned repeatedly. I took my a long time to properly integrate Crystal reports with an Isapi application through delphi. After literally weeks of research in 2004 I was able to properly utilize almost all of Crystal's functionality inside an ISAPI.

Why am I just now writing about this? Well.. As time rolls on, the technology is still viable. Especially if you have a tone of Crystal reports you'd like your users to be able to download in .Doc or .PDF formats.

Here Goes...

Import the Crystal Reports type library, save it as CRAXDRT_TLB; (into new unit) This would apply to Crystal Reports version 9. Don't forget to add the "cr" in front of the object names!!!


Here's the source code example: Please forgive any poor formatting on my part I wrote an automated .Pas to HTML conversion program, in about ten minutes, and right now it's imperfect. So I will work on that program as I continue to post Delphi Tips. Thanks and enjoy.

PLEASE LEAVE ME A COMMENT IF YOU LIKE!


---------------------------------------------------------------------------------
procedure TWebModule1.WebModule1WaExportReportAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var CrReport : Report;
NewStream : TStream;
TheReportType :CRExportFormatType;
S, TheCType : String;
begin
try


//For Initilization purposes only

TheReportType:= CRAXDRT_TLB.crEFTPortableDocFormat;

//End Initialization

////Use the value of a web page radio button to determine the type of export ////the users desires.

If TheButtonVal='PDF' then begin
TheReportType:= CRAXDRT_TLB.crEFTPortableDocFormat;
TheCType:='application/pdf'
end;
If TheButtonVal='DOC' then begin
TheReportType:= CRAXDRT_TLB.crEFTWordForWindows;
TheCType:='application/doc'
end;
If TheButtonVal='XLS' then begin
TheReportType:= CRAXDRT_TLB.crEFTExcel80;
TheCType:='application/xls'
end;
If TheButtonVal='RTF' then begin
TheReportType:= CRAXDRT_TLB.crEFTExactRichText;
TheCType:='application/rtf'
end;

///You could use the actual report name added to a select element using ///Delphi's ///FindFiles...
CrReport := Application1.OpenReport('DirectoryName\'+TheReportName);

CrReport.DiscardSavedData;
CrReport.EnableParameterPrompting:=False;
CrReport.DisplayProgressDialog:=False;
if TheButtonVal='PDF' then
CrReport.ExportOptions.PDFExportAllPages;

if CrReport.ParameterFields.Count=1 then
CrReport.ParameterFields.Item[1].AddCurrentValue(Code1);
////Depending upon any parameter values the Report uses and how they are //configured, these lines could change.
if CrReport.ParameterFields.Count=2 then begin
CrReport.ParameterFields.Item[1].AddCurrentValue(Code2);
CrReport.ParameterFields.Item[2].AddCurrentValue(Code3);
end;
CrReport.ExportOptions.FormatType :=TheReportType ;
CrReport.ExportOptions.DestinationType :=CRAXDRT_TLB.crEDTDiskFile;

/////Give the created report a destination on disk, and name
CrReport.ExportOptions.DiskFileName :=

CrReport.Export(False);

NewStream:=TFileStream.Create(the name you created above),
fmOpenRead and fmShareDenyWrite);
Response.ContentStream:=NewStream;
//IMPORTANT
Response.ContentType:=TheCType;
Response.SetCustomHeader('content-disposition', 'attachment; filename=YourShortFileName));
Except
Response.SendRedirect('Your Error Handling Page')
end;
end;
---------------------------------------------------------------------------------

Tuesday, August 12, 2008

How To "Really" Make Application Splash Screen in Delphi



Anybody else think Zarco Gajic is an idget sometimes? No seriously, I AM KIDDING. However, after looking at his how to create a splash screen in Delphi code, I realized to really make a cool splash screen in Delphi... something else would be needed.

This article will accomplish three things.

1. It will provide you code on how to prevent your application from running more than one instance.

2. It will create a splash screen that will show during your applications start up.

3. It will animate into view (fade) the splash screen. This effect although simple really adds "Splash" to your Delphi splash screen.

To Begin »

First those of you who are unfamiliar with how to view the source of your .EXE or Delphi project file simply right click in the Delphi project manager on the .exe and select view source.

That will open up the project source id the IDE editor window. Take a look at how your current source is laid out. It will appear similar to that below. Below is the full source code you will need to create the three effects outlined above.

You'll obviously need to create a new form and name it FrmSplash. Remove it from the available forms section via Projects » Options » Forms.

You'' also need to add "Windows", "Dialogs" & "Forms" if not present in the source's USES clause. Follow the code and it will dress up your Delphi application in a nice way.


-------------------------------------------------------------------------------------
program xyz;

uses
Windows,
Forms,
Dialogs,
MdiUnit in 'MdiUnit.pas' {FrmMain},

{$R *.res}

var
MyProgramNameMutex: Thandle;
I : Integer;

begin
MyProgramNameMutex:=CreateMutex(nil, False, 'MyProgramNameMutex');
if WaitForSingleObject (MyProgramNameMutex, 0) <> Wait_TimeOut then
begin
Application.Initialize;
Application.Title := 'My Program Name';
//Create Splash Screen

with TFrmSplash.Create(nil) do

try
Show;
Update;

// AnimateWindow(Handle, 1000, AW_HIDE Or AW_BLEND); Lame Code that don't work!~
for I := 0 to 255 do begin
AlphaBlendValue := I;
Sleep(10);
Application.ProcessMessages;
end;
Application.CreateForm(TFrmMain, FrmMain);

finally
Free;

end;
Application.Run;
end

else begin
MessageDlg(Application.Title+' is already running!!!', mterror, [mbok], 0);
Application.BringToFront;
Application.RestoreTopMosts;
end;
end.

-------------------------------------------------------------------------------------