I want to create a custom label package but I don't really know how to do it.
I'm doing this:
File->New->Package
And then Add->New Component
I choose the ancester type, etc. finally click on Create New Component.
I got the following unit code.
unit MyLabel1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
TMyLabel1 = class(TLabel)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard',[TMyLabel1]);
end;
end.
My Question is:
How can I set the font style like Color and Name in the code above?
When I select the custom label from the stardard pallet into a Form I want to have these properties already set.
I appreciate your help!
Thanks!
Take a look at TEnhancedPanel example in wiki.
Related
I am using Visual Studio 2013 with update 4 and Typescript 1.3 installed.
If I have a typescript file, like so:
MyEnums.ts:
export = MyEnumModule;
module MyEnumModule {
export enum AnEnum { RED, BLUE, GREEN }
}
And I have a definitions file like so:
MyDefinitions.d.ts:
declare module MyDefinitions {
interface ISomeInterface {
aProperty: string;
aMethod: () => void;
aColor: MyEnumModule.AnEnum;
}
}
I basically get an error of "Cannot find name 'MyEnumModule'"
This enum file works fine when referenced from typescript files. For instance:
SomeCode.ts:
export = MyCode;
import MyEnums = require('MyEnums');
module MyCode{
export class MyClass implements ISomeInterface {
public aColor: MyEnums.AnEnum = MyEnums.AnEnum.RED;
...and so on
My understanding is that adding either /// <reference ... or an import will not work for a .d.ts file (I tried just to be sure and it didn't appear to work either way).
Does anyone know how to reference an enum in a definition file like this?
Thanks in advance.
--Update:
Here is the error I see after trying Steve Fenton recommendations below (with a sample project I just made).
MyDefinitions.ts:
import MyEnumModule = require('../App/MyEnums');
declare module MyDefinitions {
interface ISomeInterface {
aProperty: string;
aMethod: () => void;
aColor: MyEnumModule.AnEnum;
}
}
MyEnums.ts:
export = MyEnumModule;
module MyEnumModule {
export enum AnEnum { RED, BLUE, GREEN }
}
MyClass.ts:
export = MyCode;
import MyImport = require('MyEnums');
module MyCode {
export class MyClass implements MyDefinitions.ISomeInterface {
public aColor: MyImport.AnEnum = MyImport.AnEnum.RED;
constructor() { }
aProperty: string = "";
aMethod: () => void = null;
}
}
Folder structure:
App
-MyClass.ts
-MyEnums.ts
Defintions
-MyDefintions.d.ts
Inside MyClass.ts MyDefinitions.ISomeInterface is underlined in red with hover warning "Cannot find name MyDefinitions".
I have AMD set for the project
Does anyone know how to reference an enum in a definition file like this?
There are workaround as Steve Fenton pointed out, but the system isn't designed for this. You should reference other definition files in your definition file and not reference an *implementation file * (MyEnum.ts) in a definition file.
I had a check on this and the following definition works for me, although I must admit I have never referenced "actual" code from "definition" code - but I can't think of any reason not to.
import MyEnumModule = require('MyEnumModule');
declare module MyDefinitions {
interface ISomeInterface {
aProperty: string;
aMethod: () => void;
aColor: MyEnumModule.AnEnum;
}
}
On mixing definitions and real implementations...
The type system in TypeScript is a design time and compile-time tool. When the type information is constructed at design time it makes no difference whether the type information is inferred from implementation code, taken from annotations that decorate implementations or come from an ambient declaration.
There are many use cases for mixing implementation code and ambient declarations - if you are migrating a million-line JavaScript program to TypeScript, you may not be able to migrate it from the bottom-most dependency upwards. Also, you can place ambient declarations inside of normal files - not just definition files - if you have a large program, you may not even know whether a type you place in an ambient declaration is "real" or "ambient".
The only difference between implementation code types and ambient declaration types is that the type information is right next to the implementation in real code files, and in a separate file for ambient declarations.
So... if you are having a problem using real implemented types in your ambient declaration, it is most likely caused by something that can be fixed. The example I supplied above works in a project I have in Visual Studio 2013, Update 4 - with TypeScript build configuration set to compile AMD modules. If you can share the exact details of the problem, I'm happy to help you get it working.
Having said this - if you are creating a type definition for trivial amounts of code, pasting them into a .ts file may even be faster than writing the definition - so you should make a case-by-case decision on where to spend the effort.
I am trying to add a custom property to a base form that can be accessed via the Delphi property editor. If I simply add the property as I would with a standard component the property won't show up in the property editor. Here's what I tried:
unit TestForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TfrmEasyIPBase = class(TForm)
private
FTest: String;
public
{ Public declarations }
published
property Test: String read FTest write FTest;
end;
var
frmEasyIPBase: TfrmEasyIPBase;
implementation
{$R *.dfm}
end.
Do I have to register the property at some point?
RegisterCustomModule should do the trick.
I don't have access to delphi right now but try adding your TForm descant to your project, add new form, edit the new form's pas file so it will look like
TMyNewForm = Class(TfrmEasyIPBase)
Also edit MyNewForm's DFM file - change object MyNewForm to inherit MyNewForm
Is it possible to use Resharper to refactor code such that the below method Eat is extracted into a seperate class, and the newly extracted class is injected in the Dinner class as an external dependency?
Original Code
public class Dinner
{
public Dinner()
{
}
public void Eat()
{
//do the eating
}
}
Refactored Code
public interface IEatService
{
void Eat();
}
public class EatService : IEatService
{
public void Eat()
{
}
}
public class Dinner
{
private readonly IEatService _eatService = null;
public Dinner(IEatService eatService)
{
_eatService = eatService;
}
public void Eat()
{
_eatService.Eat();
}
}
It doesn't have to be exactly as the refactored code - this is shown to give an idea.
You can do it nearly as you want in R# 7 using three-step refactoring:
Place the caret at your Eat method, invoke Extract Class refactoring (Ctrl-Shift-R in VS), name your class EatService.
Place the caret at your EatService class, invoke Extract Interface refactoring.
Place the caret at your EatService class, invoke Use Base type Where Possible refactoring.
All that is left is to fix a constructor in Dinner class so it would get IEatService as a parameter.
Using R# 6, one way to achieve this would be with this sequence of operations. Note that refactorings are available on both ReSharper | Refactor on the menu bar, or (quicker) in context with Ctrl+Shift+R. There's still a bit of typing; I wouldn't be surprised if there were a way that didn't require you to type anything at all.
Start with your Original Code in a file named Dinner.cs
With the cursor on Eat, user the Extract Interface refactoring, naming the interface IEatService
With the cursor on IEatService, Alt+Enter and create a derived type, accepting the offered name of EatService, and Alt+Enter to fill in the method implementation body
Here's where we have to type: In Dinner.Eat(), type _eatService.Eat();. Note that _eatService is red; Alt+Enter on it, choose 'Create field', change the offered type to IEatService
With the cursor on the definition of _eatService, Alt+Enter and choose 'Initialize from ctor paramater, and then Alt+Enter again and accept the readonly suggestion
Note that initialising _eatService to null is redundant; R# would let you know this.
We're now at your target code.
I think R# 7 has some new refactorings (such as Extract Class) which might make this quicker.
Here is my question, I hope that I'll write it correctly because it is a precise question.
I wonder how to use the interfaces as a contract between two modules. When I draw the module diagrams I never knows which of the modules as the circle and which has the half-open circle. A clear way on how to make the distinction would be very appreciated!
I don't want an example on how to use an interface because I know the properties of the interfaces (behaviors, etc).
Let's say that I got 2 modules, one contains the Bussiness logic, so I'll call it "Model", the other contains the GUI so I'll call it "View".
The view needs a Treeview and a Matrix on each nodes. So we got a tree-like hierarchie that the Model knows about, and for each node we want to fill a matrix of values.
root
- node1
-- leaf1
-- leaf2
- node2
- node3
-- leaf3
-- leaf4
My guts are telling me that I should do something like this:
interface IModelHierarchicMatrix {
void setTreeViewValues(TreeViewModel treeview);
void getMatrixValues();
void setMatrixValues(int[] values);
}
class Model implements IModelHierarchicMatrix {
// the code where I override the interface's function
}
So nice, we can call the needed function for the GUI at the Model. But how can we tell the GUI's class that we need that kind of behaviors (class, etc)...
I find myself often doing this kind of thing:
interface IModelHierarchicMatrixGlue {
void acceptModel(IModelHierarchicMatrix model);
}
class Gui implements IModelHierarchicMatrixGlue {
private IModelHierarchicMatrix model;
...
#Override
public void acceptModel(IModelHierarchicMatrix model) {
if (this.model == null) {
this.model = model;
}
}
}
But I always wonder if it's a good way of creating the contract between the Model and the View.
If I got to create a bi-directional contract between the Modules, how should I do that? Because it might create a cyclic logic between the interfaces...
I hope my question was clear enough, thanks in advance.
If I use /clr:oldSyntax the following should work:
public __value enum IceCreamFlavors
{
Vanilla,
Chocolate,
Sardine,
};
what is the equivalent in non-oldSyntax? How do I declare a "managed" enum in Managed C++ for .NET 2.0?
Edit:
when I follow JaredPar's advice, then if I try to pass an IceCreamFlavor to a function with the signature:
OrderFlavor(IceCreamFlavors flav)
by running
OrderFlavor(IceCreamFlavors::Sardine)
I get the error:
'IceCreamFlavors Sardine' : member function redeclaration not allowed
Try
enum class IceCreamFlavors {
Vanilla,
Chocolate,
Sardine,
};
Are you, by any chance, trying to declare your enum inside another class?
ie:
public ref class Icecream
{
public enum class flavours
{
Mint,
Vanilla,
Guac
};
};
If you are, I would guess that you need to move it out so that it is its own class instead of a nested one. (Does managed c++ allow nested classes?) My impression is that you used to be able to do it unmanaged style inside another class, but since its its own class now, you probably shouldn't be nesting them. I might be wrong. My knowledge of managed c++ and c# is kind of weak.