From d1757e8512e679c294f763f08ae54733fd88b690 Mon Sep 17 00:00:00 2001 From: Nava2 Date: Wed, 13 Jan 2010 19:11:42 +0000 Subject: [PATCH] added the .lrs, my bad. git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@408 3f818213-9676-44b0-a9b4-5e4c4e03d09d --- Projects/SAMufasaGUI/reportbug.lrs | 43 ++++++++ Units/MMLAddon/newinternets.pas | 160 +++++++++++++++-------------- 2 files changed, 125 insertions(+), 78 deletions(-) create mode 100644 Projects/SAMufasaGUI/reportbug.lrs diff --git a/Projects/SAMufasaGUI/reportbug.lrs b/Projects/SAMufasaGUI/reportbug.lrs new file mode 100644 index 0000000..2fe8211 --- /dev/null +++ b/Projects/SAMufasaGUI/reportbug.lrs @@ -0,0 +1,43 @@ +{ This is an automatically generated lazarus resource file } + +LazarusResources.Add('TFormReportBug','FORMDATA',[ + 'TPF0'#14'TFormReportBug'#13'FormReportBug'#4'Left'#3'3'#2#6'Height'#3#144#1#3 + +'Top'#3#164#0#5'Width'#3'X'#2#13'ActiveControl'#7#11'MemoSummary'#7'Caption' + +#6#12'Report a Bug'#12'ClientHeight'#3#144#1#11'ClientWidth'#3'X'#2#10'LCLVe' + +'rsion'#6#6'0.9.29'#0#7'TButton'#12'ButtonReport'#4'Left'#2#16#6'Height'#2#25 + +#3'Top'#3'p'#1#5'Width'#2'K'#7'Caption'#6#6'Report'#7'OnClick'#7#17'ButtonRe' + +'portClick'#8'TabOrder'#2#0#0#0#5'TMemo'#15'MemoDescription'#4'Left'#2#9#6'H' + +'eight'#3#168#0#3'Top'#3#192#0#5'Width'#3','#1#8'TabOrder'#2#1#0#0#6'TLabel' + +#10'LabelTitle'#4'Left'#2#10#6'Height'#2#20#3'Top'#2#12#5'Width'#2'i'#7'Capt' + +'ion'#6#12'Report a Bug'#11'Font.Height'#2#239#9'Font.Name'#6#4'Sans'#11'Par' + +'entColor'#8#10'ParentFont'#8#0#0#9'TGroupBox'#18'GroupBoxReportData'#4'Left' + +#3'H'#1#6'Height'#3'>'#1#3'Top'#2'*'#5'Width'#3#8#1#7'Caption'#6#11'Report D' + +'ata'#12'ClientHeight'#3'+'#1#11'ClientWidth'#3#4#1#8'TabOrder'#2#2#0#9'TCom' + +'boBox'#16'ComboBoxCategory'#4'Left'#2#9#6'Height'#2#29#3'Top'#2#21#5'Width' + +#3#237#0#10'ItemHeight'#2#0#9'ItemIndex'#2#0#13'Items.Strings'#1#6#15'Select' + +' Category'#6#7'Bitmaps'#6#17'Client-Image Core'#6#15'Code Completion'#6#14 + +'Colour History'#6#13'Colour Picker'#6#18'Colour Recognition'#6#3'DTM'#6#11 + +'File System'#6#13'Function List'#6#7'General'#6#3'GUI'#6#6'Input '#6#18'Int' + +'ernet Functions'#6#5'Other'#6#6'Python'#6#16'Scripting Engine'#0#8'TabOrder' + +#2#0#4'Text'#6#15'Select Category'#0#0#9'TComboBox'#23'ComboBoxReproducibili' + +'ty'#4'Left'#2#9#6'Height'#2#29#3'Top'#2']'#5'Width'#3#237#0#10'ItemHeight'#2 + +#0#9'ItemIndex'#2#0#13'Items.Strings'#1#6#15'Reproducibility'#6#6'Always'#6#9 + +'Sometimes'#6#6'Random'#6#14'Have not tried'#6#19'Unable to Reproduce'#6#3'N' + +'/A'#0#8'TabOrder'#2#1#4'Text'#6#15'Reproducibility'#0#0#9'TComboBox'#16'Com' + +'boBoxSeverity'#4'Left'#2#9#6'Height'#2#29#3'Top'#3#173#0#5'Width'#3#237#0#8 + +'BidiMode'#7#24'bdRightToLeftReadingOnly'#10'ItemHeight'#2#0#9'ItemIndex'#2#0 + +#13'Items.Strings'#1#6#8'Severity'#6#7'Feature'#6#7'Trivial'#6#4'Text'#6#5'T' + +'weak'#6#5'Minor'#6#5'Major'#6#5'Crash'#6#5'Block'#0#14'ParentBidiMode'#8#8 + +'TabOrder'#2#2#4'Text'#6#8'Severity'#0#0#9'TComboBox'#16'ComboBoxPriority'#4 + +'Left'#2#9#6'Height'#2#29#3'Top'#3#253#0#5'Width'#3#237#0#10'ItemHeight'#2#0 + +#9'ItemIndex'#2#0#13'Items.Strings'#1#6#8'Priority'#6#4'None'#6#3'Low'#6#6'N' + +'ormal'#6#4'High'#6#6'Urgent'#6#9'Immediate'#0#8'TabOrder'#2#3#4'Text'#6#8'P' + +'riority'#0#0#0#5'TMemo'#11'MemoSummary'#4'Left'#2#9#6'Height'#2'Y'#3'Top'#2 + +'@'#5'Width'#3','#1#8'TabOrder'#2#3#0#0#6'TLabel'#12'LabelSummary'#4'Left'#2 + +#10#6'Height'#2#18#3'Top'#2'*'#5'Width'#2'f'#7'Caption'#6#14'Breif Summary:' + +#11'ParentColor'#8#0#0#6'TLabel'#16'LabelDescription'#4'Left'#2#10#6'Height' + +#2#18#3'Top'#3#168#0#5'Width'#2'O'#7'Caption'#6#12'Description:'#11'ParentCo' + +'lor'#8#0#0#7'TButton'#12'ButtonCancel'#4'Left'#3#164#1#6'Height'#2#25#3'Top' + +#3'p'#1#5'Width'#3#171#0#7'Caption'#6#6'Cancel'#7'OnClick'#7#17'ButtonCancel' + +'Click'#8'TabOrder'#2#4#0#0#0 +]); diff --git a/Units/MMLAddon/newinternets.pas b/Units/MMLAddon/newinternets.pas index a053ecf..7eef06d 100644 --- a/Units/MMLAddon/newinternets.pas +++ b/Units/MMLAddon/newinternets.pas @@ -7,11 +7,11 @@ interface uses Classes, SysUtils; -const - POSTVARS_VARIABLE = 0; - POSTVARS_VALUE = 1; - type + TPostVariable = record + variable, value: String; + end; + { Store the internet connection information } @@ -20,17 +20,19 @@ type //url of the connection ConnURL: String; //contains post paramaters and vars - PostVars: array [0..1] of TStringArray; + PostVars: TList; PostFreeSpots: array of Integer; PostVarsLen, PostVarsHigh, FreeSpotsHigh, FreeSpotsLen : integer; + private + function createPostVariable(variable, value: String): TPostVariable; public constructor Create(URL: String); destructor Destroy; override; //POST variable functions for PHP transmission - procedure PostVariableAdd(theVar, theValue: String); - procedure PostVariableDel(theVar: String); - procedure PostVariableReplace(searchVar, replaceVar, value: String); - function PostHTTP: Boolean; + procedure AddPostVariable(theVar, theValue: String); + procedure DelPostVariable(theVar: String); + procedure ReplacePostVariable(searchVar, replaceVar, value: String); + function PostHTTP(out dataStream: TStream): Boolean; end; @@ -39,6 +41,7 @@ type TInternetArray = class(TObject) protected FreeSpots: array of Integer; + ConnList : TList; ConnArray: array of TInternetConnection; ConnHigh, FreeSpotsHigh, FreeSpotsLen : integer; @@ -47,10 +50,10 @@ type function ConnectionClose(ConnInd: Integer): Boolean; destructor Destroy; override; //POST variable functions for PHP transmission - procedure PostVariableAdd(connInd: Integer; theVar, theValue: String); - procedure PostVariableDel(connInd: Integer; theVar: String); - procedure PostVariableReplace(connInd: Integer; searchVar, replaceVar, value: String); - function PostHTTP(connInd: Integer): Boolean; + procedure AddPostVariable(connInd: Integer; theVar, theValue: String); + procedure DelPostVariable(connInd: Integer; theVar: String); + procedure ReplacePostVariable(connInd: Integer; searchVar, replaceVar, value: String); + function PostHTTP(connInd: Integer; out dataStream: TStream): Boolean; end; function GetPage(URL: String): String; @@ -78,6 +81,7 @@ procedure TInternetConnection.Create(URL: String); begin inherited; Self.ConnURL := URL; + Self.PostVars.Create; end; procedure TInternetConnection.Destroy; overload; @@ -85,26 +89,24 @@ begin inherited; // ADD CLOSING OF CONNECTION - // is this all necessary? Memory leaks etc trying to avoid them :p - setLength(PostVars[POSTVARS_VARIABLE], PostVars[POSTVARS_VALUE], 0); - setLength(PostFreeSpots, 0); - FreeSpotsHigh := -1; - FreeSpotsLen := 0; - PostVarsHigh := -1; - PostVarsLen := 0; + // Clear it up + PostVars.Clear; end; -procedure TInternetConnect.PostVariableAdd(theVar, theValue: String); +procedure TInternetConnect.AddPostVariable(theVar, theValue: String); var currentIndex: Integer; begin theVar := replace(' ', '%20', theVar); // more needs to be done, I only knew the ' ' replace. theValue := replace(' ', '%20', theValue); - with Self do + Self.PostVars.Add(createPostVariable(theVar, theValue)); + { with Self do begin + + if (FreeSpotsHigh = -1) then begin - setLength(PostVars[POSTVARS_VARIABLE], PostVars[POSTVARS_VALUE], PostVarsHigh + 2); + setLength(PostVars, PostVarsHigh + 2); inc(PostVarsHigh); currentIndex := PostVarsHigh; end else @@ -112,85 +114,79 @@ begin currentIndex := PostFreeSpots[FreeSpotsHigh]; dec(FreeSpotsHigh); end; - PostVars[POSTVARS_VARIABLE][currentIndex] := theVar; - PostVars[POSTVARS_VALUE][currentIndex] := theValue; - end; + PostVars[currentIndex].variable := theVar; + PostVars[currentIndex].value := theValue; + + end; } end; -procedure TInternetConnection.PostVariableDel(theVar: String); +procedure TInternetConnection.DelPostVariable(theVar: String); var i: Integer; + tempPostVar: TPostVariable; begin - for i := PostVarHigh downto 0 do + for i := (Self.PostVars.Count - 1) downto 0 do begin - if (theVar = Self.PostVars[POSTVARS_VARIABLE][i]) then + if (theVar = Self.PostVars.Items[i].variable) then begin - with Self do - begin - PostVars[POSTVARS_VARIABLE][i] := ''; - PostVars[POSTVARS_VALUE][i] := ''; - if (FreeSpotsHigh = FreeSpotsLen) then - begin - FreeSpotsLen := FreeSpotsLen + 1; - setLength(PostFreeSpots, FreeSpotsLen); - end; - PostFreeSpots[FreeSpotsHigh] := i; - end; + tempPostVar := PostVars.Items[i]; + Self.PostVars.Remove(tempPostVar); + break; end; end; end; -procedure TInternetConnection.PostVariableReplace(searchVar, replaceVar, value: String); +procedure TInternetConnection.ReplacePostVariable(searchVar, replaceVar, theValue: String); var - i: Integer;; + i: Integer; + tempPostVar: TPostVariable; begin with Self do begin - for i := PostVarHigh downto 0 do + for i := (PostVars.Count - 1) downto 0 do begin - if (searchVar = PostVars[POSTVARS_VARIABLE][i]) then + tempPostVar := PostVars.Items[i]; + if (searchVar = tempPostVar.variable) then begin - PostVars[POSTVARS_VARIABLE][i] := replaceVar; - PostVars[POSTVARS_VALUE][i] := value; + tempPostVar.variable := replaceVar; + tempPostVar.value := theValue; + break; end; end; end; end; -function TInternetConnection.PostHTTP: Boolean; +function TInternetConnection.PostHTTP(out dataStream: TStream): Boolean; var // holds the vars when they are placed together URLData: String; - theStream: TStream; + tempPostVar: TPostVariable; begin try with Self do begin //ADD Connection stuffs - for i := PostVarsHigh downto 0 do + for i := (PostVars.Count - 1) downto 0 do begin - if (PostVars[POSTVARS_VARIABLE] <> '') then + tempPostVar := PostVars.Items[i]; + if (tempPostVar.variable <> '') then begin - URLData := URLData + format('%d=%d+', [PostVars[POSTVARS_VARIABLE][i], - PostVars[POSTVARS_VALUE][i]]); + URLData := URLData + format('%d=%d+', [tempPostVar.variable, + tempPostVar.value]); end; end; Delete(URLData, Length(URLData) - 1, 1); {I DONT KNOW (TStream), this should work since we don't reuse it after.} - HttpPostURL(ConnURL, URLData, theStream); + dataStream := nil; + HttpPostURL(ConnURL, URLData, dataStream); // Lets remove all Post Variable data so fresh start next time. - setLength(PostVars[POSTVARS_VARIABLE], PostVars[POSTVARS_VALUE], 0); - setLength(PostFreeSpots, 0); - FreeSpotsHigh := -1; - FreeSpotsLen := 0; - PostVarsHigh := -1; - PostVarsLen := 0; + PostVars.Clear; end; except - raise Exception.createFMT('TInternetConnection.PostHTTP: Something went wrong, could not complete. (%d)', URLData); + raise Exception.createFMT('TInternetConnection.PostHTTP: Something went wrong, could not complete. URL: %d', URLData); exit(false); end; result := true; @@ -205,19 +201,11 @@ function TInternetArray.ConnectionOpen(URL: String): Integer; var currentIndex: Integer; begin - with Self do - begin - if (FreeSpotsHigh = -1) then - begin - setLength(ConnArray, ConnHigh + 2); - inc(ConnHigh); - currentIndex := ConnHigh; - end else - begin - currentIndex := FreeSpots[FreeSpotsHigh]; - dec(FreeSpotsHigh); - end; - ConnArray[currentIndex].Create(URL); + try + Result := Self.ConnList.Add(TInternetConnection.Create(URL)); + except + raise Exception.createFMT('TInternetArray.ConnectionClose: Could not close connection %d URL: %d', + [theInd, ConnURL]); end; end; @@ -225,8 +213,14 @@ end; Close the connection, add the index to the FreeSpots. } function TInternetArray.ConnectionClose(theInd: Integer): Boolean; +var + tempConn: TInternetConnection; begin try + tempConn := Self.ConnList.Items[theInd]; + Self.ConnList.Remove(tempConn); + tempConn.Destroy; + { with Self do begin ConnArray[theInd].Destroy; @@ -236,10 +230,10 @@ begin setLength(FreeSpots, FreeSpotsLen); end; FreeSpots[FreeSpotsHigh] := theInd; - end; + end; } except raise Exception.createFMT('TInternetArray.ConnectionClose: Could not close connection %d URL: %d', - [theInd, ConnArray[theInd].ConnURL]); + [theInd, ConnList.Items[theInd].ConnURL]); exit(false); end; result := True; @@ -252,7 +246,7 @@ end; procedure TInternetArray.PostVariableAdd(connInd: Integer; theVar, theValue: String); begin try - result := ConnArray[connInd].PostVariableAdd(theVar, theValue); + ConnList.Items[commInd].PostVariableAdd(theVar, theValue); except raise Exception.createFMT('TInternetArray.PostVariableAdd: %d is not in the ConnArray', [connInd]); @@ -266,7 +260,7 @@ end; procedure TInternetArray.PostVariableDel(connInd: Integer; theVar: String); begin try - result := ConnArray[connInd].PostVariableAdd(theVar); + ConnList.Items[commInd].PostVariableAdd(theVar); except raise Exception.createFMT('TInternetArray.PostVariableDel: %d is not in the ConnArray', [connInd]); @@ -280,13 +274,23 @@ end; procedure TInternetArray.PostVariableReplace(connInd: Integer; searchVar, replaceVar, value: String); begin try - result := ConnArray[connInd].PostVariableAdd(searchVar, replaceVar, value); + ConnList.Items[commInd].PostVariableAdd(searchVar, replaceVar, value); except raise Exception.createFMT('TInternetArray.PostVariableReplace: %d is not in the ConnArray', [connInd]); end; end; +function TInternetArray.PostHTTP(connInd: Integer; out dataStream: TStream): Boolean; +begin + try + result := ConnList.Items[commInd].PostHTTP(dataStream); + except + raise Exception.createFMT('TInternetArray.PostHTTP: %d is not in the ConnArray', + [connInd]); + end; +end; + { OTHER } function GetPage(URL: String): String; var