Hi is there any equivalent method in classic ASP for C#.net function "System.Convert.ToByte" ?
basically i am encoding one string in my windows app using c#. and in classic asp it need to be decoded in which it need to use the above function.
Thanks,
Vinod
Perhaps I'm missing something important here but how about int=Val(ch) and ch=Chr(int)?
Also and as I'm sure you already know, converting the characters in a C# string into bytes will fail for any string containing anything outside of the extended ASCII range, i.e. 00=NUL to FF='ΓΏ'.
Related
Is it possible to evaluate an OleVariant of type varArray (Data of TClientDataset) using Delphi evaluator? I'm trying to build a Debugger Visualizer, using ToolsApi, for this kind of type. I work in an application that uses this extensively to transport data from client to server, and this would be really nice! I tried to work with pointers, evaluating TVarData(variable).VType and TVarData(variable).VArray, and then casting then to pointers, but the pointer is not valid in the api.
When I have a TClientDataset variable in the debugging code, this is not necessary, because we already have an extention using ToolApi to visualize the dataset (calling SaveToFile in evaluator). But we have too many code that have only the data variable.
So my question is: is there a way to do this with multiple evaluations, like converting the varArray to string and then unserialize the result in the api (visualizer)?
I saw this answer that could convert the OleVariant to string, but does not say anything about converting back to OleVariant.
I'm using this post as an example of a visualizer.
I'm working with some legacy code that uses ParamCount() and ParamStr() in various places, and now I need to provide different values than those that were actually passed as command line variables.
The simplest solution would be to programmatically add/modify the existing command line parameters, since the alternative is to change A LOT of the legacy code to accept function parameters rather than directly accessing ParamCount() and ParamStr().
Is this possible? Can I somehow add/modify parameters from within the program itself so that ParamCount() ParamStr() will pick up my new/modified parameters?
Edit, clarification of the legacy code:
The legacy code makes some database requests, using where arguments from the command line (and sanitizing them). This is fine in 99.9% of all cases, as these arguments are fundamental for the purpose of the legacy units. However, I'm working on a new feature that "breaks the mold", where one of these fundamental arguments are unknown and need to be fetched from the database and provided internally.
Yes, I could search and replace, but my objective here is to not touch the legacy code, as it's in a unit that is shared among many different programs.
Restarting the program and/or executing a new copy of it from itself is one solution, but seems a bit risky and cumbersome. This is a production program that executes on a server and needs to be as simple and robust as possible.
Is this possible? Can I somehow add/modify parameters from within the program itself so that ParamCount() ParamStr() will pick up my new/modified parameters?
Technically yes, but it is not something that the RTL itself exposes functionality for, so you will have to implement it manually.
Since you are working with legacy code, I'm assuming you are working on Windows only. In which case, ParamStr() and ParamCount() parse the string returned by the Win32 API GetCommandLine() function in kernel32.dll.
So, one option is to simply hook the GetCommandLine() function itself at runtime, such as with Microsoft's Detours, or other similar library. Then your hook can return whatever string you want 1.
1: for that matter, you could just hook ParamCount() and ParamStr() instead, and make them return whatever you want.
Another option - which requires messing around with lower-level memory that you don't own, and I don't advise doing this - is to obtain a pointer to the PEB structure of the calling process. You can obtain that pointer using NTQueryInformationProcess(ProcessBasicInformation). The PEB contains a ProcessParameters field, which is a pointer to an RTL_USER_PROCESS_PARAMETERS struct, which contains the actual CommandLine string as a UNICODE_STRING struct. If your altered string is less then, or equal to, the length of the original command line string, you can just alter the content of the ProcessParameters.CommandLine in-place. Otherwise, you would have to allocate new memory to hold your altered string and then update ProcessParameters.CommandLine to point at that new memory.
I am using VS 2010; all these days I am confortable runnig code analysis on class libraries.
But for a web application, the UI control names with prefixes like ddl, pnl, etc are causing code analysis warnings as "Correct the spelling...". I googled and think this can be addressed using rulesets; but didn't find a way to suppress these..any pointers ?
You could add them to a custom dictionary.
Why are you using those prefixes?
The most common reason I've seen people give for this is "Hungarian Notation." However, as I've tried to point out in a number of jobs over the years, "you're doing it wrong." Within an IDE like VS 2010, is there any real reason to prefix every DropDownList instance with "ddl"? Both you and the IDE know it's a DropDownList. There's no question or confusion about that.
The idea behind Hungarian Notation isn't to "prefix every variable with a shorthand of its class" but rather to "prefix every variable with what it is." What something is doesn't have to mean its class or type, it's more an idea of what that object intuitively represents. Sure, it's a DropDownList. But what does that DropDownList mean? Is it part of a particular grouping of elements in the UI? That grouping's designation would provide a lot more information than "ddl" ever would.
As an example, say I have an application with various connection strings. In a given method in my DAL, I store one of them in a variable called strConnection. Well, that's adhering to the notation, but it's not telling me anything important. I know it's a string. (I can see its declaration, I can mouse over it in the IDE, etc.) And I know it's a connection string based on its usage. But which one is it? What part of the business does it serve? If instead it was called connstringHR then I could immediately infer that it's the connection string for the HR database.
I need to use the JSON parser in my iPhone application. We have API's which are used to parse the data.
I just want to know, how can we do without using any API ?
Thank you.
Use the APIs.
Use the APIs.
Use the APIs.
They're quick, they've been tested to work, and you don't have to think about them.
If you're still committed to writing a JSON parser (and/or if this is an academic pursuit), then you're likely to benefit from researching the JSON specification and brushing up on [your platform of choice]'s string operations and regular expressions library. Then, as #alexanderb suggests, create a small library of classes and/or functions to support you.
Yes, you can. Since JSON is a simple string, you could create your own parser that is able to serialize string to target object.
For instance, you have JSON like that
{ description: "my description", value: 10 }
You can extract description value, by regex and return object of class, like
class Target
{
string Description;
int value;
}
But, of cause it always a good idea to use time-proven JSON parsers.
Copy the 8k of these 238 lines (+/- comments) into your code:
http://code.google.com/p/json-sans-eval/source/browse/trunk/src/json_sans_eval.js?r=12
I am trying to write a function that takes any TList and returns a String representation of all the elements of the TList.
I tried a function like so
function ListToString(list:TList<TObject>):String;
This works fine, except you can't pass a TList<String> to it.
E2010 Incompatible types: 'TList<System.TObject>' and 'TList<System.string>'
In Delphi, a String is not an Object. To solve this, I've written a second function:
function StringListToString(list:TList<string>):String;
Is this the only solution? Are there other ways to treat a String as more 'object-like'?
In a similar vein, I also wanted to write an 'equals' function to compare two TLists. Again I run into the same problem
function AreListsEqual(list1:TList<TObject>; list2:TList<TObject>):boolean;
Is there any way to write this function (perhaps using generics?) so it can also handle a TList<String>? Are there any other tricks or 'best practises' I should know about when trying to create code that handles both Strings and Objects? Or do I just create two versions of every function? Can generics help?
I am from a Java background but now work in Delphi. It seems they are lately adding a lot of things to Delphi from the Java world (or perhaps the C# world, which copied them from Java). Like adding equals() and hashcode() to TObject, and creating a generic Collections framework etc. I'm wondering if these additions are very practical if you can't use Strings with them.
[edit: Someone mentioned TStringList. I've used that up till now, but I'm asking about TList. I'm trying to work out if using TList for everything (including Strings) is a cleaner way to go.]
Your problem isn't that string and TObject are incompatible types, (though they are,) it's that TList<x> and TList<y> are incompatible types, even if x and y themselves are not. The reasons why are complicated, but basically, it goes like this.
Imagine your function accepted a TList<TObject>, and you passed in a TList<TMyObject> and it worked. But then in your function you added a TIncompatibleObject to the list. Since the function signature only knows it's working with a list of TObjects, then that works, and suddenly you've violated an invariant, and when you try to enumerate over that list and use the TMyObject instances inside, something's likely to explode.
If the Delphi team added support for covariance and contravariance on generic types then you'd be able to do something like this safely, but unfortunately they haven't gotten around to it yet. Hopefully we'll see it soon.
But to get back to your original question, if you want to compare a list of strings, there's no need to use generics; Delphi has a specific list-of-strings class called TStringList, found in the Classes unit, which you can use. It has a lot of built-in functionality for string handling, including three ways to concatenate all the strings into a single string: the Text, CommaText and DelimitedText properties.
Although it is far from optimal, you can create string wrapper class, possibly containing some additional useful functions which operate on strings. Here is example class, which should be possibly enhanced to make the memory management easier, for example by using these methods.
I am only suggesting a solution to your problem, I don't agree that consistency for the sake of consistency will make the code better. If you need it, Delphi object pascal might not be the language of choice.
It's not cleaner. It's worse. It's a fundamentally BAD idea to use a TList<String> instead of TStringList.
It's not cleaner to say "I use generics everywhere". In fact, if you want to be consistent, use them Nowhere. Avoid them, like most delphi developers avoid them, like the plague.
All "lists" of strings in the VCL are of type TStringList. Most collections of objects in most delphi apps use TObjectList, instead of templated types.
It is not cleaner and more consistent to be LESS consistent with the entire Delphi platform, and to pick on some odd thing, and standardize on it, when it will be you, and you alone, doing this oddball thing.
In fact, I'm still not sure that generics are safe to use heavily.
If you start using TList you won't be able to copy it cleanly to your Memo.Lines which is a TStringList, and you will have created a type incompatibility, for nothing, plus you will have lost the extra functionality in TStringList. And instead of using TStringList.Text you have to invent that for yourself. You also lose LoadFromFile and SaveToFile, and lots more. Arrays of strings are an ubiquitous thing in Delphi, and they are almost always a TStringList. TList<String> is lame.